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
else
	MoveForward = false
end

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:
https://devforum.roblox.com/t/how-do-i-detect-if-a-player-is-moving-backwards/1935426/26?page=2
https://devforum.roblox.com/t/contextactionservice-with-more-than-one-input/1151496

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