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

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

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

✓ 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.

2 comments

0

Thank you very much ^^

0

No problem.

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