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

[FE] How to detect Player Amount?

Asked by 5 years ago

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
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"? fredfishy 833 — 5y

2 answers

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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!"
0
didn't work :l MarkHasReset 77 — 5y
0
Did you get an error? What was your output? chomboghai 2044 — 5y
Ad
Log in to vote
0
Answered by
Launderer 343 Moderation Voter
5 years ago

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.

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. Launderer 343 — 5y

Answer this question