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

How to know which player pressed a key?

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.

1 comment

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

1 answer

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

1 comment

0

You are using an unsupported method of getting the player's mouse. You are recommended to use UserInputService.

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