Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to have different wait times in the same loop?

I'm trying to do a few things in a loop that need to have different wait times. They need to be in the same loop so I can't just make a second loop. Here's an example of what I mean:

while wait() do
	--here do something every wait()
	player.Score = player.Score + 1
	
	--here do something once a second
	timer = timer + 1
	wait(1)
end

1 answer

If you use spawn, you can run code in a separate thread, thus allowing the script to do multiple things at once. For example:

spawn(function()
	while wait() do
		--do first thing
	end
end)
while wait(1) do
	--do other thing
end

these two loops would be executed simultaneously, allowing you to do something at both intervals.

This discussion is preserved as it was. New answers, comments, and votes are closed.