Let me explain it a bit. I only want the players inside of the lobby to teleport so i added a variable that would constantly check in a while wait() do loop, how many players are inside of the lobby. With if statements.
Now my problem is that it keeps counting up it keeps counting the players who have already been counted, so for example one player in the lobby keeps adding the variable until it is 5, then the game starts because the variable is equal to 5. Any ideas how i can fix this?
Would this work? (its not very complicated wrote in like 2 mins)
local Counter = 0 while true do for i,v in pairs(game.Players:GetPlayers()) do print("looping") Counter = Counter + 1 end print("counter") print(game.ServerStorage.Counter.Value) game.ServerStorage.Counter.Value = Counter print(game.ServerStorage.Counter.Value) wait(1) Counter = 0 end
I would advise to use a more efficient solution than the one above.
local PlayerCount -- this will be the amount of players that will be in your game at all times. local function UpdateCount() PlayerCount = #game.Players:GetChildren() end game.Players.PlayerAdded:Connect(UpdateCount) game.Players.PlayerRemoving:Connect(UpdateCount)