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?
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
1 | local oxygen = script.Parent.Oxygen |
2 |
3 | function change () |
4 | script.Parent.Text = oxygen.Value |
5 | end |
6 |
7 | script.Parent.Oxygen.Changed:Connect(change) |