I have a repeating function that is supposed to loop every 20 seconds. I want it to ask the "if Foliage.Anchored == false" part every time but it seems from running it that after the first time that Anchored == false, when the loop is run it assumes its false every time. Any ideas on why this is? If you need me to clarify anything let me know, thanks!

function mainLoop()
	local Tree = script.Parent.Parent.DEPOSIT
	local Foliage = Tree:FindFirstChild("Small Foliage")
	while true do
		if Foliage.Anchored == false
		then clearDeposit()
		generateDeposit()
		wait(20)
			else wait(20)

			end
		end
end
generateDeposit()
mainLoop()

2 comments

0

Maybe you should use while wait(20) just after calling generateDeposit function?

0

I solved it, It was because I had the variables before the while loop instead of after it.