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

I am getting an error on my script. The error is about MouseButton1Click. Could Someone Help me?

Asked by 4 years ago
Edited 4 years ago

I am trying to make a menu for my game.

This is my code

01local function onClick()
02 
03    script.Parent.Visible = false
04    script.Parent.Parent.MainMenu.Visible = true
05 
06 
07end
08 
09script.Parent.MouseButton1Click:Connect(onClick)
10script.Parent.SettingsButton.MouseButton1Click:Connect(onClick)

This is the error: MouseButton1Click is not a valid member of Frame "Players.FireTap1.PlayerGui.MenuGui.Menu"

2 answers

Log in to vote
0
Answered by 4 years ago

Your script is fine, the issue is what you're referencing.

1script.Parent.MouseButton1Click:Connect(onClick)

The error is saying MouseButton1Click isn't applicable to Frames, because they cant be clicked. You need to reference an imagebutton or a textbutton instead.

0
Thank you very much! FireTap1 12 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You got a error, you need to detect the visiblity, heres the script am mean:

01local function onClick()
02 
03    if script.Parent.Parent.MainMenu.Visible == true then
04     script.Parent.Parent.MainMenu.Visible = false
05   else
06     script.Parent.Parent.MainMenu.Visible = true
07     end
08 
09 
10end
11 
12script.Parent.MouseButton1Click:Connect(onClick)
13script.Parent.SettingsButton.MouseButton1Click:Connect(onClick)

If you don't want to make it visible when it falls (button opens an invisible frame then visible then again), Heres another script:

01local function onClick()
02 
03    if script.Parent.Parent.MainMenu.Visible == true then
04     script.Parent.Parent.MainMenu.Visible = false
05     end
06 
07 
08end
09 
10script.Parent.MouseButton1Click:Connect(onClick)
11script.Parent.SettingsButton.MouseButton1Click:Connect(onClick)

Hope it help's!

Answer this question