Problem with a player counting script

I am trying to make a player count script but it won’t display the player count like it’s still 0 even if i join the game

the script :

while wait() do
	script.Parent.Value = #game.Players:GetChildren()
end

:arrow_down_small: This is what happens when I launch the game
image

:arrow_down_small: the location of the script
image

:arrow_down_small: the value properties
image

3 Likes

try doing script.Parent.Value = #game.Players:GetPlayers()

Or you could just add to the value when a player joins and minus when a player leaves

1 Like
while true do
	script.Parent.Value = #game:GetService("Players"):GetPlayers()
    task.wait()
end
1 Like

I’ve tried the two solutions, it did not work somehow

1 Like

It’s still not working
But i think i know where the problem is
I think the script works but the value isn’t updating to the player count

1 Like
local nv = script.parent

game.Players.PlayerAdded:Connect(function()
	nv.Value+=1
end)
game.Players.PlayerRemoving:Connect(function()
	nv.Value-=1
end)
1 Like

Ok i’ve got the solution
Somewhat ReplicatedStorage doesn’t allow server scripts / Local scripts to run, like only module scripts can run in ReplicatedStorage
So I moved the script in ServerScriptService
But thanks for y’alls help :slight_smile:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.