Please do not post Wiki related stuff, unless its Extremely Necessary and Will help me majorly!
I have a Player Value in Work space so I need it to gain a certain amount of players but to do it over and over and check so.
1 | while wait( 0.1 ) do |
2 | --Script Here-- |
3 | end |
You can get all the players in the server by using the GetPlayers()
method in the Players
service, which will return a table of the players.
If I wanted to count the number of players:
1 | local numPlayers = 0 |
2 | local Players = game:GetService( "Players" ) |
3 |
4 | for _, player in pairs (Players:GetPlayers()) do |
5 | numPlayers = numPlayers + 1 |
6 | end |
7 |
8 | print "There are " .. tostring (numPlayers) .. " players in the server right now!" |
Create a script, not a local script, regular script. Put it in Workspace or ServerScriptService. Create a NumberValue and put it in the script. Now write this in the script
1 | game.Players.PlayerAdded:Connect( function (Player) |
2 | local PlayerCount = script:WaitForChild( "NumberValue" ) |
3 | PlayerCount.Value = PlayerCount.Value + 1 |
4 | end ) |
5 |
6 | game.Players.PlayerRemoving:Connect( function (Player) |
7 | local PlayerCount = script:WaitForChild( "NumberValue" ) |
8 | PlayerCount.Value = PlayerCount.Value - 1 |
9 | end ) |
So basically the value of the NumberValue is the amount of Players in the server at all times. You're welcome.