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)
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Thanks.
Remember to upvote positive answers and also mark an accepted answer for future visitors..