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
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.
The script is halting because of the waits, to get around this please look up coroutines, they can run in another priority without halting the rest of the script.
Here's a link to get you started
http://wiki.roblox.com/index.php/Beginners_Guide_to_Coroutines