I’m trying to make a system where if suddenly a player leaves during this while wait() do statement, the loop will reset.
I’m using a PlayerRemoving function for this since I don’t know how I can infinitely check every second inside the while wait() do loop (but if you do that could help solve this)
local currentCount = #game.Players:GetChildren()
while wait(1) do
if #game.Players:GetChildren() >= currentCount then
-- do whatever it is you wanna do
end
end
This only checks once through the entire loop. I need something that infinitely checks through the loop and when the check actually happens, It will restart the loop.
Dude, clearify your problems better. Once again, while wait(1) do is infinite, so whatever you write inside it it checks infinitely. You cant restart it, because it doesnt have an ending
You can put your loop inside a function, and when you wanna restart it, break the loop and call the function again (You can call a function inside the same function thus creating sort of an artificial loop)
local loopBool = true
local function repLoop()
loopBool = true
while loopBool == true do
wait(1)
if #game.Players:GetChildren() < currentCount then
loopBool = false
repLoop()
end
end
end
repLoop()
So now, were back to how I can infinitely check a variable inside the loop WITHOUT roblox events I guess since they don’t allow loop based functions inside the code. So how can I constantly check?
while task.wait(1) do
repeat task.wait(1) until #game.Players:GetPlayers() >= 2
game.Players.PlayerRemoving:Wait()
if #game.Players:GetPlayers() < 2 then
continue
end
end