(Help) Script suddenly stops working

I have a code for the npc but its not working, The while wait() function does not work as well.

If i delete the yellow part(in studio when the game is not running) the script works when i hit play.
Capture

Place2 - Copy.rbxl (92.5 KB)

I believe the issue occurs from line lines 109-111, namely
image

When the yellow wall is added, it results in wall being nil.
I assume you want it to just end that iteration of the loop and go to the next iteration, in which case you should use continue rather than return.
You may also need to add a wait() statement into it, as I’m unsure how it will act when doing while wait() do

e.g.

if wall == nil then
	task.wait() -- acts like wait(), but is better
	continue
end

Works but, i dont understand why return holds it and wont exit the function?

To be honest, I would have expected return to cause an error, but for some reason it just causes an infinite yield. It’s possible that it is a Roblox bug, in which case it may need to be reported.

Alright i will file a bug report. thank you!

Wait, is return suppose to break a loop? like while wait() loop or while true do wait()?

I believe that it’s meant to error, as it’s not in the scope of a function.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.