So, for a game, I wanted to use a function that fires every time a player presses one. Except, it must be a specific player. Is there any way that I can figure out the player that is doing the input, during the event of InputBegan and InputEnded?
COMMUNITY QUESTION
How do I determine the player who input the key in UserInputService?
1 answer
UserInputService is a service only accessible in localscripts, and localscripts can also view a property of the Players service that tells you what player the script is owned by
local player = game.Players.LocalPlayer -- the player
local uis = game:GetService("UserInputService")
uis.InputBegan:connect(function()
print(player.Name..' pressed something')
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Are you sure that they can only be accessed in LocalScripts? I used it on a normal script, and it worked perfectly, but only while running in Studio.
Yes, It'll work in studio but as soon as you do a server test or run it in game it won't work. It's best to not ever use it in server scripts