Worth using a wait() if it slows generation way down?

Hello! I am making an island generation system and have a little problem.

When generating islands, my script uses a While loop. While testing my script had a bottleneck Wait() but when I was testing I accidently removed the wait and when I ran it it took a few seconds but then it was all generated.
To get to the point, While loop with a wait command takes 250x times longer then no wait command but it’s not a good practice to have no wait() command

Is it okay that I have no wait() or is there something I can do? The wait() makes the island probably take 15+ minutes whilst no wait makes it pretty much instant.

1 Like

can you explain yourself better?

well if you dont have a wait inside a while loop itll just crash. But if you want speed you can do

local rs = game:GetService(‘RunService’)

while true do
rs.Heartbeat:Wait()
end

Which would make it run as fast as run service generally would.
2 Likes

He’s asking if it’s a good idea to not have any yielding functions in a while loop.

@TheSleepyScripter for your answer, it’s simply no. If there’s no yielding in a repetitive code, it has a high chance to give out a script exhaustion execution error. To fix this, you can actually replace wait() with the new task library task.wait(). More info about it here.

This helps, with around double speed to a normal wait(). I think I will just have to use smaller generation but thanks anyway!

It depends, if your while loop runs too long then it will be terminated for exhausting the timeout allocation, if your while loop runs long then add a yield, but if it doesn’t then it can work most likely without a yield

It **DOES** work with a while loop and does not get terminated but it is a bad way to handle the script.