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

How to know which player pressed a key?

Asked by 3 years ago

So I am trying to do a script (located in ServerScriptService) that detects if a key is pressed so it will call a function, but I don't know how to get the name of the player who pressed it.

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then 
        print("fireball pls")
    end 
end)

I can't use LocalPlayer since it's a server-sided script.

0
This won't function either way. This service is client-side only, as stated in it's documentation. I suggest you use a RemoteEvent/Function, with a parallel cooldown Ziffixture 6913 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

user input service and getmouse() only work on the client so you will need to set up a remote event and localscript to detect when a player presses a key

0
You are using an unsupported method of getting the player's mouse. You are recommended to use UserInputService. KadenBloxYT 135 — 3y
Ad

Answer this question