local Tablet = script.Parent
local clickDetector = Tablet.Parts.Button.ClickDetector
function onMouseClick()
if Tablet.Screen.SurfaceGui.Frame.Visible = false then
Tablet.Screen.SurfaceGui.Frame.Visible = true
elseif Tablet.Screen.SurfaceGui.Frame.Visible = false
end
clickDetector.MouseClick:connect(onMouseClick)
✓ ANSWER ACCEPTED
I need help with my on/off button script ? It doesn`t work just like it have to do
1 answer
✓ Accepted answer
The main problem in the code is this part:
elseif Tablet.Screen.SurfaceGui.Frame.Visible = false
You are using an "elseif" statement instead of a plain "else" statement. "elseif" is used to write another "if" statement if conditions on a previous "if" statement are not met. Here is your edited code. Also, be sure to use "==" instead of "=" if you are placing conditions.
local Tablet = script.Parent
local clickDetector = Tablet.Parts.Button.ClickDetector
local function onMouseClick()
if Tablet.Screen.SurfaceGui.Frame.Visible == false then
Tablet.Screen.SurfaceGui.Frame.Visible = true
else Tablet.Screen.SurfaceGui.Frame.Visible = false
end
clickDetector.MouseClick:connect(onMouseClick)
P.S. Please indent your code correctly. It would be useful in the future.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thank you very much ^^
No problem.