Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

1 comment

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

2 answers

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)

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) 

This discussion is preserved as it was. New answers, comments, and votes are closed.