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

How do I Disable certain movement keys?

I want to make a 2D game that only allows you to move left, right and jump. I've tried searching for this topic but I got no help (Basically I want to disable W & S movement keys) . Also I've heard its got something to do with

local UserInputService = game:GetService('UserInputService')

Any help appreciated :D

1 answer

✓ Accepted answer

hey bud, ContextActionService is what you're looking for. but here you go

local CAS = game:GetService("ContextActionService")
local FREEZE_COMMAND  = "Stunned"

CAS:BindActionAtPriority(
	FREEZE_COMMAND,
	function() 
		return Enum.ContextActionResult.Sink
	end,
	false,
	Enum.ContextActionPriority.High.Value,
	Enum.KeyCode.W,
	Enum.KeyCode.S
	)

--CAS:UnbindAction(FREEZE_COMMAND)
--this is just if you ever want to re-enable movement in the Z axis

just an important tip, you're gonna want to restrict the camera's movement too, but i can't really help with that

2 comments

0

Thanks a lot!! :D

0

Where Would You Put That script? ServerScriptService?

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