Open / close sign

im kinda a beginner scripter but i kinda wanna know how to do this. Im making a sign that when you click a button in switches between open/close. So far when i click the clickdetector the letters on the surface gui go red and the text changes to “closed” but now, how do i switch it back? how do i tell the computer to go back and forth between open and closed? i though an if statement would work but idk

local click = script.Parent
local text = game.Workspace.dis1.screen.SurfaceGui.main
local x = 3
click.MouseClick:Connect(function()
	text.Text = "CLOSED"
	text.TextColor3 = Color3.new(1, 0, 0.0156863)
	print("closed")
	x = 4
	
end)

if x == 4 then
	click.MouseClick:Connect(function()
		text.Text = "OPEN"
		print("opened")
		x = 3
	end)
end

(its a border map im making :eagle::eagle::eagle:)

Basically, you would need to know whether or not the sign is closed to get the sign to read the right text. This is really easy though as the text would say whether it is closed to turn the sign back open when you click. You would want to do this instead in one MouseClick event, and use if statements for the check:

click.MouseClick:Connect(function()
		if text.Text == "OPEN" then
			text.Text = "CLOSED"
			text.TextColor3 = Color3.new(1, 0, 0.0156863)
			print("closed")
		else
			text.Text = "OPEN"
			print("opened")
			x = 3
		end
	end)

You can also do this with variables like I see you are trying to do above; however, the if statements must be inside the event because the outside part just connects the function to the MouseClick; it does not check for the condition every time a click occurs.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.