"Attempt to index nil with MouseButton1Click"

Hi.

So while I was play-testing, I kept stumbling across the error “Attempt to index nil with MouseButton1Click” on all the scripts in a specific GUI.

The script:

Button = script.Parent
Player = game:GetService("Players").LocalPlayer
Mouse = Player:GetMouse()

Button.MouseButton1Click:connect(function()
-- code under here works fine
end)

Any help would be appreciated, thanks!

Button needs to be an ImageButton or TextButton

It is a TextButton though.
char limit

send a screenshot of explorer please

image
Here.

does the button get deleted at any point

no, there is no point where the button gets deleted

any of its ancestors get deleted?

not either
char limitation is frustrating

Ensure that it’s a LocalScript and that the button doesn’t gets deleted at any point.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Button = script.Parent

Button.Activated:Connect(function()
	
end)

It is in a local script, and the button never gets deleted.

if the code inside the button MouseButton1Click is working then the error cant be from that script it must be from somewhere else make sure the error is not from another script

The error only happens sometimes, on multiple different scripts. I’d say there is a 7/10 chance of getting it for me.

Could you record a video of it, and send it here? (Make sure you have output enabled)

Here you go:

Please take a screenshot of the error, I cannot see anything in your video. :slight_smile:

The localscript is inside the button. So it wouldn’t error telling you that button is nil, if button get’s deleted, because the thread that the localscript is in will stop, since it’s a descendant of the button.

image
Here you go.

That’s not the same script location as the one you showed above with the explorer screenshot.

The error is in Handler inside BallCam, please show us the hierchy of Ballcam/Handler in the explorer tab. And the script.