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

player count display script?

Asked by 4 years ago

I need a script that displays the specified roblox place's player count in a textlabel for one of my games

The place would be specified by an id, and would be inside the same universe as the game w/ this script in it

A lot of people have also requested a script similar to this

Would anybody like to share their knowledge?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Thank you to RayCurse for creating the code, you can see his post here.

Although this is a script helping site not a script developing site, I can give some advice.

Inside a script, you can use this to count the current amount of players:

local playerCount = #game.Players:GetPlayers()

GetPlayers() returns a table of all Players objects. The # (length operator) is used to get the length of the table returned.

Then use that information to set a textlabel's text to that amount. (using tostring(), since we're dealing with numbers not strings.)

Now for updating the amount for whenever someone enters or leaves the game.

We can use the following code:

game.Players.PlayerAdded:Connect(function() -- When a player joins
    playerCount = playerCount + 1 -- Adds 1 to "playerCount"
    -- Update textlabel
end)

game.Players.PlayerRemoving:Connect(function() -- When a player leaves
    playerCount = playerCount - 1 -- Removes 1 from  "playerCount"
    -- Update textlabel
end)

To detect when a player is joining and leaving the game.

Hopefully this answered your question!

If I have incorrectly answered this, feel free to correct me in the comments of this answer.

Ad

Answer this question