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

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

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

✓ Accepted answer

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.

1 comment

0

Thank you very much!

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!

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