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.
while wait(0.1) do --Script Here-- 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:
local numPlayers = 0 local Players = game:GetService("Players") for _, player in pairs(Players:GetPlayers()) do numPlayers = numPlayers + 1 end 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
game.Players.PlayerAdded:Connect(function(Player) local PlayerCount = script:WaitForChild("NumberValue") PlayerCount.Value = PlayerCount.Value + 1 end) game.Players.PlayerRemoving:Connect(function(Player) local PlayerCount = script:WaitForChild("NumberValue") PlayerCount.Value = PlayerCount.Value - 1 end)
So basically the value of the NumberValue is the amount of Players in the server at all times. You're welcome.