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

Display Number of Players in a Game within a Gui?

Hi there, I'm new to Lua so I'm struggling as to how I go about doing this, I've looked around online and no ones seemed to have asked this before so I'll ask here, hopefully someone can help out there!

So for my game I've got a game as a 'hub', where players play this game and within that they use a Gui to teleport to other games. When players are choosing what game to teleport to, the plan was to have a 'Number of Players within game' count on each teleport button, so players can see how many players are playing each game. On paper this sounds straightforward, but I genuinely have no idea how to get that info through scripting. Any help here would be greatly appreciated!

1 comment

0

If you're new to Lua, I suggest you look at Alvinblox's Beginner Scripting tutorials. Don't try to go too big from the start.

3 answers

This is really simple, all you need is a IntValue and PlayerAdded.

Create an IntValue inside ReplicatedStorage and name it whatever you like.

Now,set it's value to the amount of players in game inside PlayerAdded, you can do this by simply doing :

local intValue = game:GetService('ReplicatedStorage').IntValueName

game.Players.PlayerAdded:Connect(function()
intValue.Value = #game.Players:GetPlayers()
end)

You can also add to it's value, i don't think it would effect it.

Now inside a textlabel, you can use .Changed and set the text to the amount of players in the server.

local intValue = game:GetService('ReplicatedStorage').IntValueName
local textLabel = script.Parent

intValue:GetPropertyChangedSignal('Value'):Connect(function()
textLabel.Text = 'PLAYERS IN GAME:'.. tostring(intValue.Value)
end)

2 comments

0

lol my man doesnt even indent hahah

0

yea because I was typing it here and for some reason tab doesnt work

Hey I would like to give you a script but you are biting of more then you can chew! If you dont Know Roblox itself has a nice tutorial that goes from easy things to crazy stuff!

If I told you what to do you would be confused! You will just copy and paste my script. The Point is to learn!

Hope you understand.

Also Here is the series: https://www.youtube.com/playlist?list=PLuEQ5BB-Z1PJ4JIDXpttxuvCzJMeIqzMi

1 comment

0

tbh some people (like me) learn from scripts

A much more simple answer is to insert a textlabel in your gui and add this script in the textlabel:

game.Players.PlayerAdded:Connect(function()
     script.Parent.Text = "There are "...#game.Players:GetChildren().." players."
end)

game.Players.PlayerRemoving:Connect(function()
     script.Parent.Text = "There are "...#game.Players:GetChildren().." players."
end)

This script will run every time a player joins and every time a player leaves. When it runs, it will update the text to say how many players there are.

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