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

How to end a loop when all the player's scripts are disabled?

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

2 answers

✓ Accepted answer
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

1 comment

0

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.

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

1.PlayerAdded

  1. CharacterAdded

  2. Variable

  3. Loops

I hope this helped you in any way. :)

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