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 3 years ago
Edited 3 years ago

I am trying to make a menu for my game.

This is my code

local function onClick()

    script.Parent.Visible = false
    script.Parent.Parent.MainMenu.Visible = true


end

script.Parent.MouseButton1Click:Connect(onClick)
script.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 3 years ago

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

script.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 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

local function onClick()

    if script.Parent.Parent.MainMenu.Visible == true then
     script.Parent.Parent.MainMenu.Visible = false
   else
     script.Parent.Parent.MainMenu.Visible = true
     end


end

script.Parent.MouseButton1Click:Connect(onClick)
script.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:

local function onClick()

    if script.Parent.Parent.MainMenu.Visible == true then
     script.Parent.Parent.MainMenu.Visible = false
     end


end

script.Parent.MouseButton1Click:Connect(onClick)
script.Parent.SettingsButton.MouseButton1Click:Connect(onClick)

Hope it help's!

Answer this question