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.
What is the issue? I have no idea how to make the script and i haven’t found any tutorials on it.
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!
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.
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
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.
-- 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 works tho? id like to make a board that counts up everytime player joins so you know how many players have joined while the server has been up. i could take the - out and it should be it but since me not know how script then i dont know how to connect it with text label