Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

3 comments

0

why not add in a if statement to check if the player has already been added?

0

Can you give me an example of how i need to do that? I cannot figure it out

0

BaconX112X are you trying to teleport them somewhere else from the Starting Place?

2 answers

✓ Accepted answer

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

2 comments

0

This worked, thank you!

0

glad it worked : )

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.