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

[FE] How to detect Player Amount?

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

1 comment

0

#game:GetService("Players"):GetChildren() seems to be what you require? You might want to filter for things that are definitely players with :IsA("Player"). However, not 100% what the question is asking. What do you mean "Player value in workpace"?

2 answers

✓ Accepted answer

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!"

2 comments

0

didn't work :l

0

Did you get an error? What was your output?

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.

1 comment

0

With this you don't need stupid while loops and stuff, this is all you need right here. So forget your script you were making.

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