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

(SOLVED) How do you change a TextLabel's text in a local script?

Asked by 5 years ago
Edited 5 years ago

I have a LocalScript inside a GUI. I am trying to change the text of a TextLabel. I want the text to say: $0 / $4000. It only says 0. (That's the text it is before playing.)

This is the LocalScript:

local player = game.Players.LocalPlayer
local cashCollected = player:WaitForChild("CashCollected")
local storage = player:WaitForChild("Storage")

script.Parent.RewardText.Text = "$"..cashCollected.Value.."/"..storage.Value

cashCollected:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.RewardText.Text = "$"..cashCollected.Value.." / $"..storage.Value
end)

Any help?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

From a LocalScript, you can access the LocalPlayer's PlayerGui and make edits from there:

local player = game.Players.LocalPlayer
local cashCollected = player:WaitForChild("CashCollected")
local storage = player:WaitForChild("Storage")

player.PlayerGui.ScreenGui.RewardText.Text = "$"..cashCollected.Value.."/"..storage.Value -- Fix #1

cashCollected:GetPropertyChangedSignal("Value"):Connect(function()
    player.PlayerGui.ScreenGui.RewardText.Text = "$"..cashCollected.Value.." / $"..storage.Value -- Fix #2
end)
Ad

Answer this question