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

How to I make a loop that will reset itself if something happens in the middle?

I'd like to make a game loop script that'd restart on a condition, say like a player disconnects from the game in the middle of a battle, and the next lines are reliant on the player object existing, how do I just reset the script?

1 answer

✓ Accepted answer

The command break will break out of a loop. What you could do is have the entire loop in another loop, so when you break out of the game loop, the outside loop will make sure the game loop restarts. This is what I mean:

while wait() do
	--Everything in this loop will keep going when break is called on the enclosing loop
	while wait() do
		--Game loop stuff
		if not condition then
			break
		end
	end
end

1 comment

0

Thanks!

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