I've heard that if you do not yield in a while loop, it tends to break. In matter fact, I believe it was one of this websites tip of the day. In my game, my round script breaks after a couple of rounds, so I'm wondering if this is the issue. Anyways, can anyone explain how you yield in a while loop? Thanks! :)
By yield
, they meant that your script will stop executing for a while before continuing. This is most commonly done with a wait
command, like this:
local n = 0 while true do wait(1) n = n + 1 end
If you were to take out the wait(1)
, you would be instructing lua to stay in the loop forever -- which means that Roblox wouldn't be able to update physics, display graphics, or run other scripts. This is why Roblox usually freezes when you have a loop like this.
Other ways of yielding include coroutine.yield()
, calling any function that is labelled as a yield function (ex DataStore's YieldFunctions), or ending the thread (via 'error' or just finishing executing the code).