attempt to index local 'mouse' (a nil value)

Error on line 2422

Came up into my output when I ran a script. These are whats used.

local Player = game.Players.RandomPlayerNameHere
local mouse = Player:GetMouse()

Then skip to line 2422 (where the error is):

mouse.KeyDown:connect(function(key) -- Line 2422 
	if key == "z" and attack == false then
 attack1()
	end
end)



mouse.KeyDown:connect(function(key)
	if key == "x" and attack == false then
		 attack2()
	end
	end)



mouse.KeyDown:connect(function(key)
	if key == "v" then

if autofind == false then
autofind = true
else 
autofind = false		
end

end
end)

And I have 0 clue as to what I've done wrong. If you need to see any other parts of the script I'd be happy to oblige. Any ideas as to how to fix this is appreciated.

4 comments

0

GetMouse is only available locally.

0

You're using a server script, or you're generally not using the LocalPlayer. Basically, use a LocalScript.

0

Look at contextactionservice and then fire remote events when a player clicks one of the buttons.

0

jeez line 2422 thats a big script