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

How To Combine Several Repeat Loops?

So I am working on a game with nukes, and below are some of the ways I detect the location of each player and determine if they are able to survive. All of the code works however, I ran into an issue when there are multiple players, the repeats will repeat until that player is dead and then it will effect the others. How can I make it so that everyone takes damage at the same time?

for _, player in pairs(game.Players:GetPlayers()) do
	if player.Character then
		if player.CurrentLocation.Value == "Bunker1" and bunkerOne.DoorClosed.Value == false then --If bunker one door is open
			repeat
				wait(1)
			game.Workspace[player.Name].Humanoid.Health = game.Workspace[player.Name].Humanoid.Health - 10
			until game.Workspace[player.Name].Humanoid.Health == 0 or bunkerOne.DoorClosed.Value == true
		else
			if magnitude <= maxDistanceBunker1 and player.CurrentLocation.Value == "Bunker1" then --If another player is in vault one
				repeat
					wait(1)
					game.Workspace[player.Name].Humanoid.Health = game.Workspace[player.Name].Humanoid.Health - 10
				until game.Workspace[player.Name].Humanoid.Health == 0
			end
		end		
	end
end
end

2 answers

✓ Accepted answer

You could wrap what’s inside the first for loop in a spawn() function. This makes a new thread so the main thread isn’t blocked.

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