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

a keybinding script is not functioning?

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("W was pressed")
	end
end
 
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.W)

im trying to get keyboard input from the player, I tried using some code from a wiki page. I switched it to a localscript because it threw an error running on a normal script. after that there were no errors but the script would not run. if I need to change it to be FE compatible how would I do it?

1 answer

✓ Accepted answer

#Reasoning & Solution


This will be quick, don’t worry. This is unfunctional as you can’t define ContextActionService by simply writing game.. You have to use the :GetService() method of game to get Services now. Simply create a variable referencing this Service, and use that instead:

local ContextActionService = game:GetService("ContextActionService")

--// Function

ContextActionService:BindAction() -- Insert arguments.

If you’re unfamiliar with the term “arguments”, please see this website to learn more, for now, just paste what was in the parentheses beforehand into the parentheses again.


Hope this helps! If so don’t forget to accept this answer!

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