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

Updating a Text Label via lua?

Asked by 7 years ago

So I've added a text label in the StarterGui and what it basically is supposed to do is just keep track of how many players are currently online.

At default, I kept the text in the label at "Players: 0/12".

When I try and update the text the properties of the label shows it is updated, but visually it isn't updated.

Also I don't add in the wait in the beginning, the value of the total players would just be 0...

Also if this means anything, I'm in ROBLOX studio, but I have tried it on play mode on the level.

wait(0.1)
local players = game.Players:GetPlayers()
local screenGUI = game.StarterGui.ScreenGui
local screenGuiTLabel = game.StarterGui.ScreenGui.TextLabel
local playercount = "Players: " .. #players .. "/12"

function updatePlayerlist()
    screenGuiTLabel.Text = playercount
end

game:GetService("Players").PlayerAdded:connect(updatePlayerlist)

Thank you!

1 answer

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
7 years ago

In your script, you are modifying descendants of the StarterGui service, not the real copies of the descendants which belong to each Player and which will be rendered on screen.

StarterGui has a special function, which is to copy its contents into each Player's personal PlayerGui when they join the game or when they spawn. If you modify the contents of StarterGui, you will change what each player sees when they join the game or when they respawn, but you won't change what each player sees at that moment.

You should keep track of the players and update the text in a LocalScript, making sure to manipulate the copies under game.Players.SomePlayer.PlayerGui rather than their template counterparts in StarterGui.

0
Alright so I should create a new GUI after the player joins in the path you specified by getting the name of the player and substitute that name with 'SomePlayer' in the path you gave me above? Platinum19126 9 — 7y
0
You don't need to create a new GUI, ROBLOX will do that for you. Add a new line at the top player = game.Players.LocalPlayer, then change line 3 to screenGUI = player.PlayerGui.ScreenGui, and change line 4 to screenGuiTLabel = screenGUI.TextLabel duckwit 1404 — 7y
0
Thanks a ton! Platinum19126 9 — 7y
Ad

Answer this question