Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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?

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 WiryReally 3 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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.

Ad

Answer this question