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

How do you make a text changer with a SurfaceGUI?

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??

1 comment

0

You need to use a LocalScript to make changes on Guis, but dont put the LocalScript in the Workspace, place it in a Client-Specific Area, like StarterGui, you'll have to manually input the "text" and "opened" variables

1 answer

✓ Accepted answer

Values and References


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.

Application


With that said, you can do the following:

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!

1 comment

0

open.Value == true ..............

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