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

Why won't my surface GUI text change to the value?

Asked by 5 years ago

I'm trying to make a text that's on a surface GUI change to whatever the integer value is, but it doesn't change at all.

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

text = ""..val

Thanks if you can help.

0
let me get this straight, the script is in the textbox and the NumberValue/Intvalue is parented by the script too? becuase if script.Parent.Text is the textbox then you forgot to add another .Text or else you are trying to set the instance to a number rather setting the text property to the number fanofpixels 718 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

You need to add an event so it fires and runs the code.

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

val.Changed:connect(function() --Fires when the value changes
text = val.Value --Sets the text to the value
end)
Ad
Log in to vote
0
Answered by 5 years ago

This is because you are setting your variables to the VALUE of the property, not the property itself.

The variable is set to the value of the property at the time, so instead of adding a .Value or a .Text remove it.

Do this instead:

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

text.Text = tostring(val) -- we will preset the value. 

val.Changed:Connect(function() -- Put this in a changed event so it runs when the value changes.
    text.Text = tostring(val)
end) 

Answer this question