Here is what I tried.. but it lead me to another question..
while true do wait(1) script.Parent.CurrencyFrame.Money.Text = "$".. script.Parent.CurrencyFrame.Money.Amount.Value end)
I am trying to update the text label to the value of the amount script.Parent.CurrencyFrame.Money.Amount.Value
But also always have a $ sign a front of the number. How would I make it so it formats correctly?
You can just use the Changed
event of the Value
object. Every time it fires, update the TextLabel text. Simple as that!
local label = script.Parent.CurrencyFrame.Money local value = label.Amount value.Changed:connect(function() label.Text = "$" .. value.Value end)
Note that we set the variables to the objects themselves, not the properties. If we would have set it to the properties, the variable would become the primitive datatype that the property is and would not reference the property in the object. If you don't know what that means, look at this:
local part = Workspace.Part part.Name = "Hello" local a = part.Name print(a) --> Hello part.Name = "Goodbye" print(a) --> Hello print(part.Name) --> Goodbye
First of all, while loops are generally bad, so let's find your value and use the .Changed event
local money = script.Parent.CurrencyFrame.Money.Amount
next we attach an anonymous function to it like this.
money.Changed:connect(function() end)
between that we can then run any code, in your case set the text
money.Parent.Text = "$"..money.Value
putting this altogether gets you this.
local money = script.Parent.CurrencyFrame.Money.Amount money.Parent.Text = "$"..money.Value money.Changed:connect(function() money.Parent.Text = "$"..money.Value end)