I have an opening/closing system for a bank. I have a BoolValue inside Workspace. The value is called opened. This value determines if the bank is opened or closed. If the value is true, than the bank is open. If the value is false, the bank is closed. I also have a Part in the workspace with a SurfaceGui. Inside that, there is a TextLabel. I have a Script inside the TextLabel. I used the :GetPropertyChangedSignal()
function, but it didn't work.
I think I messed up with the script, but I don't know.
Here's the script:
local text = script.Parent.Text local open = script.Parent.Parent.Parent.Parent.Opened open:GetPropertyChangedSignal("Value"):Connect(function() if open.Value == true then text = "Opened" else text = "Closed" end end)
Any help??
The problem here if that your text variable is a value
, not a reference
.
The problem with using a value and not a reference, is that the value isn't attached to the object itself. Thus, if you change anything in the object, the value doesn't update.
With that said, you can do the following:
```lua local t = script.Parent local open = script.Parent.Parent.Parent.Parent.Opened
open.Changed:Connect(function() if open.Value then t.Text = "Opened" else t.Text = "Closed" end end) ```
Keep in mind here as objects such as the boolvalue
only have one property of importance, it is ok to use the Changed event instead of GetPropertyChangedSignal()
. For all other types of objects, you should use the GetPropertyChangedSignal function
Hopefully this helped, be sure to accept if it did!