Need help with Context Action Service detecting player actions

First of all I want to detect when the player moves forward or backward with Context Action Service. The problem is that I can’t assign a keybind to W/S because the player stops moving.

The code I have written so far:

local CAS = game:GetService("ContextActionService")
local MoveForward = false

CAS:("Forward", handleAction, false, Enum.KeyCode.W)

if actionName == 'Forward' then
	MoveForward = true
	MoveForward = false

What’s the need for ContextActionService? You can use Humanoid.Running combined with Humanoid.MoveDirection for this.

I need it for a run script. I tried UIS too but isn’t working because i use CAS for detecting if player is pressing left shift and only updates when i press any key binded to CAS. With this i want to prevent the player running backwards and side to side.

The solution was very simple, just add another key to the CAS:

CAS:BindAction("Run", handleAction, false, Enum.KeyCode.LeftShift, Enum.PlayerActions.CharacterForward)

And now Shift + W (And A or D) works, useful links about this:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.