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

How do I make numbers from a value also show in a GUI text?

Asked by 5 years ago

Im trying to make the number also show in GUI text this is the script I tried but didn't work.

while true do
    game.StarterGui.ScreenGui.Money.TextLabel.Text = game.Players.LocalPlayer.leaderstats.Money.Value
    wait()
end

1 answer

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

StarterGui and PlayerGui; Not the Same

Some beginners may find this to be a quick way to change a Gui for all players. Unfortunately, it's not that simple. StarterGui is basically what PlayerGui clones from when you respawn. That means, any changes you make to objects in StarterGui will not show until you respawn.

Taken from the Common Mistakes blog post.

With that in mind, you will be changing the Text from the PlayerGui. You also should not be using a while loop to do something a Changed event should be doing.

local client = game:GetService("Players").LocalPlayer
local player_gui = client:WaitForChild("PlayerGui")
local leaderstats = client:WaitForChild("leaderstats")

leaderstats.Money.Changed:Connect(function(new_value)
    player_gui.ScreenGui.Money.TextLabel.Text = tostring(new_value)
end)

Hope this helps!

Ad

Answer this question