Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

when using userinputservice how do i reference the player who pressed a key?

so when using userinputservice to detect when a player presses a key how do i reference that player who pressed the key and send the info of who had pressed the key to another script.

So a example of what i mean is,if i want to create a fighting game,and i want a wall to appear in front of the player when he/she presses Q'

How do i find out which player pressed Q?

1 comment

0

I think this is not so difficult because the Userinput works in a local script and when interacting with the event you can find out who clicked

1 answer

There isn’t a need to do this. UserInputServce can only be used within a Local environment, meaning it will only function on your local machine. There is always and only one associated Player Object to said machine, and that is yours. You will always have the Player that initiated the Input since it will always call back to the LocalPlayer

If you wish to communicate to a ServerScript when the InputObject KeyCode matches Q, you can simply fire a RemoteEvent from ReplicatedStorage to the ServerScript. No need to send any Player Object whatsoever as the .OnServerEvent will already be provided with the Client that fires the Event within the first parameter.

This discussion is preserved as it was. New answers, comments, and votes are closed.