fixed foreach bug on custom scripts