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

Why does this text label change with the first value, but not change any other time?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a GUI that changes along with a value, but it only changes the first time.

local text = script.Parent
local val = script.Parent.cash.Value

text.Text = tostring(val) 

val.Changed:Connect(function() 
    text.Text = tostring(val)
end) 

Thanks if you can help.

0
Sorry, I messed the title up. I mean the text label changes only one time. CaptainAlien132 225 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

DO NOT USE A LOOP (this is to the previous answer)

The reason it doesn't work is that the variable val is an actual number. You can't do .Changed on a number. Here is a complete fix:

local text = script.Parent
local val = script.Parent.cash

text.Text = val.Value

val.Changed:Connect(function() 
    text.Text = val.Value
end) 

When using Variables to define a value, do not put .Value at the end. This is because you want a updating value. The current value will always stay the same if you use the Variable again.

Hopefully, this helped you solve your problem!

If you have any errors Comment below.

Best of luck developer!

0
It still doesn't change CaptainAlien132 225 — 5y
0
Maybe because your value isn't changing? BlackOrange3343 2676 — 5y
Ad

Answer this question