How to end a loop when all the player's scripts are disabled? Thanks!
local i = 1
local Players = game.Players:GetPlayers()
repeat
--Code
until Players.PlayerGui.LocalScript.Disabled == true
How to end a loop when all the player's scripts are disabled? Thanks!
local i = 1
local Players = game.Players:GetPlayers()
repeat
--Code
until Players.PlayerGui.LocalScript.Disabled == true
AllDisabled = false
while wait(0.5) do
for i,v in pairs(game.Players:GetChildren()) do
if v.PlayerGui.Script.Disabled == true then -- if one is enabled then script break and
break -- return to the while wait() do
end
AllDisabled = true -- Will be triggered if all are disabled.
break
end
You don't require a loop to accomplish this. :P (At least, not a while loop anyways... (>->) )
You could just simply use the PlayerAdded event to listen for when a player connects, and use the CharacterAdded event (for a player) to listen for when the player's character spawns, and respawns. \(^-^/)
It will look similar to this:
game.Players.PlayerAdded:connect(function(plr) -- Variable "plr" represents the player that connected to the server
plr.CharacterAdded:connect(char) -- Variable "char" represents the player's character that has (re)spawned
-- Code
end) -- Ends event/code-chunk
end)-- Ends event/code-chunk
I'm not going to write a full script, but this should help you, + it's much better than using a loop! :D (+ May have your game run faster! :O )
Stuff touched on but didn't get into great detail on
I hope this helped you in any way. :)
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Why do you need a while loop to get this result? You could just simply use the for loop, unless it's in a server-side, but even then, you could use the CharacterAdded event/ etc. + You didn't explain the reasoning behind your answer: why should he do it like that? What does one do, and what role does one do? etc.