Player Count GUI

  1. What do you want to achieve? I would like to make a GUI that shows how many players there are in the current server, i’ve searched YouTube but found nothing.

  2. What is the issue? I have no idea how to make the script and i haven’t found any tutorials on it.

  3. What solutions have you tried so far? I’ve tried to search YouTube, but as i said earlier, i found nothing.

Please just send me some help on how to make the script, thanks!

3 Likes

Fast code, im sure it works

local Players = 0

game.Players.PlayerAdded:Connect(function(Player)

Players = Players + 1

end)

game.Players.PlayerRemoving:Connect(function(Player)

Players = Players - 1

end)

Just use the :GetPlayers method on Players Service, which returns a table of all player instances and then the length of that table using the # operator is your number of players in the server.


@EncodedCheetah that really is just adding extra works + 2 extra connections.

1 Like

Shall i just put that in my GUI or do i have to do something more? Sorry, i’m pretty new to scripting.

He din’t said its a local script so i did it fast in 30 seconds bro, dont expect the best code in that time

Put a local script inside your gui

while wait(1) do
	local players = game.Players.NumPlayers
	if players >= 2 then
		wait()
		script.Parent.Text = "Players: "..players.." "
	else
		wait()
		script.Parent.Text = "Players: "..players.." "
	end
end
1 Like
local text = script.Parent

while wait() do

text.Text = #game.Players:GetPlayers().." are in the server!"

print(#game.Players:GetPlayers().." are in the server!")

end

I didn’t expect you to take it as a complaint, I just meant to advice you. Well anyways, I will just say, you don’t need a localscript to use that function and if something is improving your knowledge, you should actually learn from it instead of taking it as a complaint towards you.


Also I don’t get how your latest reply’s code works, it will basically result with a nil error.

Did i take all you said as a complaint? I just told you i did that in 30 seconds, what you can expect from that, i already know scripting, im just trying to help people with basic codes, i wont write 100 lines just for a player count gui, last code is deprecated but works

Sorry if you didn’t meant to take it as a complaint, I probably just assumed it because of the language. Anyways my bad then.

Also, if you did that as in 30 seconds then just take some more time and you may come up with a better solution? I don’t really recommend giving deprecating solutions but works probably till a point.

But just wanted to point out, you don’t need to write 100 lines, you just need to show how to get the count, it can be done in one line, although not the cleanest code:

print(#game.Players:GetPlayers())

I don’t really want to continue anything to off-topic anymore, as it doesn’t really help.

1 Like

I suggest you to learn more basics of scriptings first.

You could just do something like

-- When the script first runs
local text = #game.Players:GetPlayers()
game.Players.PlayerAdded:Connect(function()
    -- To avoid while loops
    text = #game.Players:GetPlayers()
end)

- - If another player joins at the same time
if tonumber(text) ~= #game.Players:GetPlayers() then text = #game.Players:GetPlayers() end

game.Players.Changed:Connect(function()
     “TextLabel”.Text = text
end)

Not the most efficient code, but its a tad bit better than a while loop constantly playing.

It would be much less taxing performance wise by avoiding while loops and simply updating it when another player joins. It’s not alot but still.