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

Whenever I earn money in my game it doesn't update?

Asked by 9 years ago

Okay, so whenever I earn money in my game it updates in the value but not in the Gui. Here is the script:

Money = script.Parent.Parent.Money
local s = Instance.new("ScreenGui")
s.Parent = script.Parent
local m = Instance.new("TextLabel")
m.Parent = s
m.BackgroundTransparency = 1
m.Position = UDim2.new(0,0,0,400)
m.Size = UDim2.new(0,200,0,50)
m.Font = "Legacy"
m.FontSize = "Size24"
m.TextColor3 = Color3.new(36,216,48)
m.Text = "$" .. Money.Value

If you can help, thank you!

1 answer

Log in to vote
2
Answered by
Sublimus 992 Moderation Voter
9 years ago

Using the code you already provided, we can add a .Changed event that runs whenever Money's value changes.

Money = script.Parent.Parent.Money
local s = Instance.new("ScreenGui")
s.Parent = script.Parent
local m = Instance.new("TextLabel")
m.Parent = s
m.BackgroundTransparency = 1
m.Position = UDim2.new(0,0,0,400)
m.Size = UDim2.new(0,200,0,50)
m.Font = "Legacy"
m.FontSize = "Size24"
m.TextColor3 = Color3.new(36,216,48)
m.Text = "$" .. Money.Value

Money.Changed:connect(function() -- When money's value changes, run the contained function
    m.Text = "$"..Money.Value -- Changes the text to reflect the change
end) -- End the function

Changed Event

0
Thank you! It worked LostInCode 30 — 9y
Ad

Answer this question