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

Way To Check For Players?

Asked by
Scootakip 299 Moderation Voter
8 years ago

Is there a way for a script to check how many players are in a game?

In my game there's a glitch where if there's only 1 player in the game, they can get as many points as they want. I need some way for the game to check if they're at least 2 players. I'd use that to tell the script to only do its regular cycle if there is more than 1 player in the game. I tried using a way to detect the number of players on a team, but the way the script is structured, it always just ended up breaking the script.

Just wondering if there's a way and if you can link me to some resources so I can learn how.

1 answer

Log in to vote
0
Answered by 8 years ago

There are multiple ways: - Use the # operator in conjunction with :GetPlayers(). - Use game.Players.NumPlayers.

For the # operator in conjunction with :GetPlayers().

local NumPlayers = #game.Players:GetPlayers();

In your case, you would need to check it before the game starts, don't get confused with the server starting and the game starting. The actual gameplay you've scripted is what I'm talking about.

This is what I think you would need to use:

print("Waiting for two or more players to begin the game.");
repeat wait() until #game.Players:GetPlayers() > 1; --You could do >=2 as well.
print("The game is now starting!");
0
So on line 2 it would be something like if NumPlayer >= 2 then ?? Scootakip 299 — 8y
0
Yeah, pretty much GlitchMasta47 7 — 8y
0
It doesn't seem to be working. Even with 2 players it still thinks it's not enough players. Scootakip 299 — 8y
0
Well, not entirely. The reason it probably isn't working is because you're getting the amount of players when the server is created (assuming you're using a ServerScript). Before you start the game, check it. PowerHotmail123 90 — 8y
Ad

Answer this question