Hello and welcome! You didn’t actually post any code. If you are redefining functions inside a loop, you have to make sure those are anonymous functions, as named functions are defined once only.
See this related issue Same code in if and else blocks, get UndefVarError only on else condition