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

I'm trying to make a GUI that has the same text as a value, but it doesn't change. Help?

I'm trying to make a GUI that displays a value. I put the value in the text label and this is my script.

local oxygen = script.Parent.Oxygen.Value

script.Parent.Oxygen.Changed:Connect(function() script.Parent.Text = oxygen end)

for some reason when the value changes the text label does not change. How am I supposed to make this?

2 answers

✓ Accepted answer

This issue is somewhat common. Don't define the oxygen value there. Define the oxygen variable inside the function. Another solution is doing script.Parent.Text = script.Parent.Oxygen.Value. When setting a variable to a value's value, it gets set when/where it is defined and that is it. When setting a variable to the object, it becomes what i call an object reference.

local part = workspace.Part part and workspace.Part are the same thing. You can do part.Color=(color) or workspace.Part.Color=(Color) and it will do the same thing. But when you do local val = workspace.NumVal.Value with the workspace.NumVal's value being 10, val becomes 10. If workspace.NumVal's value gets updated, val will not change until re-defined

I'm new to scripting and I don't know if this will work but here is what I got

local oxygen = script.Parent.Oxygen

function change ()
	script.Parent.Text = oxygen.Value
end

script.Parent.Oxygen.Changed:Connect(change)

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