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