game.Players.PlayerAdded:connect(function(player) mouse = player:GetMouse() mouse.KeyDown:connect(function() print("Success") end) end)
Why do I get the error:
error trying to index global 'mouse' (a nil value)
GetMouse
only works from a LocalScript
, so it wouldn't work in general using the PlayerAdded
event.
Mouse is client side issue, meaning you must use a Local script in order to use this script. Place a LocalScript in StarterGui or StarterPack, and place this code;
plr =script.Parent.Parent mouse=plr:GetMouse() mouse.KeyDown:connect(function() print("Success") end)