So here's an example of what I made
local p = game.Players.NumPlayers while true do if p > 0 then --This is where my code is end wait() end
But instead of going through an entire loop it stops when the player count is at 0 and never checks if it changed.
game.Players.PlayerAdded:connect(function(player) -- Detect the player joining, and fire function with the player instance -- Your code here end
Here's the solution: update the variable in the while loop otherwise it will stay at 0 because that's what it was assigned.
while wait() do --Put your "p" in the while loop local p = game.Players.NumPlayers if p > 0 then print("--This is where my code is") end end
Or keep it outside
local p = game.Players.NumPlayers while wait() do p = game.Players.NumPlayers if p > 0 then print("--This is where my code is") end end