Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I need help with my on/off button script ? It doesn`t work just like it have to do

Asked by 3 years ago
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)

1 answer

Log in to vote
0
Answered by
DemGame 271 Moderation Voter
3 years ago
Edited 3 years ago

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.

0
Thank you very much ^^ pinopeltzi 7 — 3y
0
No problem. DemGame 271 — 3y
Ad

Answer this question