Hi ScriptingHelpers community,
I saw that this question have been made before but I'll be glad if some of you can answer it anyway so I can understand better what am I doing wrong.
I have this script in order to print on the terminal when the player press a Key Down and the same thing when the Key is Up:
local PlayersService = game:GetService('Players')
local LocalPlayer = PlayersService.LocalPlayer
Mouse = LocalPlayer:GetMouse()
function KeyUp(key)
if (key == "q") then
print('Key is Up')
end
end
function KeyDown(key)
if (key == "q") then
print('Key is Down')
end
end
Mouse.KeyUp:connect(KeyUp)
Mouse.KeyDown:connect(KeyDown)
The problem is that when I run the game with the script it says:
- ServerScriptService.Script:4: attempt to index field 'LocalPlayer' (a nil value)
I have the script on the 'ServerScript' folder and I also tried with the 'StarterPlayerScripts' folder but the same error appears. What am I missing?.
I'm new with this hole thing called 'Roblox Scripting' and I don't know a lot of things about the API so I'll be glad if some of you can answer my question.
In the meantime, thank you so much for your attention.

1 comment
Did OldPalHappy answer your question? Please click Accept Answer just below the comments section of his post.