Hi all,
I am trying to make a wall GUI (using SurfaceGUIs) to control the lights in my hotel room, and I think I know how. The only problem is I cant seem to get it to know its clicked in the first place. This is my script:
local text = script.Parent.TextLabel
local Button = script.Parent
Box = script.Parent.Parent.Box
function onClick()
text.Text = "On"
text.Text = "Off"
end
Button.MouseButton1Click:connect(onClick)
I currently am only trying to get the text to change, so I know that it is working.
Any help would be appreciated, im sure its a really simple fix however i am unsure. Any help would be greatly appreciated!
You might need to apply some variable to your script first.
local text = script.Parent.TextLabel
local Button = script.Parent
Box = script.Parent.Parent.Box
local Enabled = false
function onClick()
if not Enabled then
Enabled = true
text.Text = "On"
else
Enabled = false
text.Text = "Off"
end
end
Button.MouseButton1Click:connect(onClick)
I added a variable name Enabled and it will change its value once someone click on it to true then it will change back to false after someone click on it again and then true and so on.
(Sorry for my bad explanation about this)
Forgot to mention that I sort out the stuff in the gui and script too
heres the new script
local text = script.Parent.TextLabel
local Button = script.Parent.TextButton
local Enabled = false
text.Text = "Off"
function onClick()
if not Enabled then
Enabled = true
text.Text = "On"
else
Enabled = false
text.Text = "Off"
end
end
Button.MouseButton1Click:connect(onClick)
local text = script.Parent.TextLabel
local Button = script.Parent
local Enabled = false
text.Text = "Off"
function onClick()
if not Enabled then
Enabled = true
text.Text = "On"
else
Enabled = false
text.Text = "Off"
end
end
Button.MouseButton1Click:connect(onClick)