So i have a game script that picks a random player and then runs code into that player. After a certain amount a time, that loop would end and a new player is picked. The problem is tho, when the player leaves it would obviously break the script and i don't know how to get it to stop and reset after the player leaves. –
Here is some example code for what i'm using.
while true do
wait(0.5)
local plr = game.Players:GetChildren()
if #plr > 1 then
local Pick = plr[math.random(1, #plr)]
if Pick.Character then
local char = Pick.Character
--Code and stuff
end
else
--Makes a Gui message saying at least two players are needed
end
end

1 comment
Quick way is to use a global variable and check if it's changed (not efficient tho)