Hello, I'm doing a recursive function, on some models and inside there are other models and part, well then it throws me an error of stack overflow, and the script stops working, what can I do to fix it ?, I'm new and it's not that know a lot, thanks.
function ChildEdi()
for i, child in pairs(model:GetChildren()) do
if child:IsA("BasePart") then
child.Touched:Connect(onModelTouched)
elseif child:IsA("Model") then
ChildEdi(child)
end
end
end
ChildEdi(model)

4 comments
The stack overflow is because you are calling the function over and over again because you never go "deeper." There will always be a child that is a model becuase you are just calling the same function over again with the same model
Local functions can be called recursively.
Please accept Phlegethon's answer
thanks