Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Any ideas on how i can check if so many players are in a lobby?

Asked by 4 years ago

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?

0
why not add in a if statement to check if the player has already been added? NovaMagic 73 — 4y
0
Can you give me an example of how i need to do that? I cannot figure it out BaconX112X 75 — 4y
0
BaconX112X are you trying to teleport them somewhere else from the Starting Place? Primrose_Studio 53 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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
0
This worked, thank you! BaconX112X 75 — 4y
0
glad it worked : ) NubScripters 126 — 4y
Ad
Log in to vote
0
Answered by
SmartNode 383 Moderation Voter
4 years ago
Edited 4 years ago

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)

Answer this question