When not facing forward, the player tends to dash ONLY forward or backwards if looking sideways

Hello everyone!!

I’m working on a dash script that lets the player dash depending on what direction they’re moving at. The issue with the script is that it works perfectly fine when dashing while looking forward but if I dash if not facing forward then it still dashes forward. It also dashes me back when looking sideways.

--[[SERVICES]]--
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local Debris = game:GetService("Debris")

--[[PLAYER MODEL]]--
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
local RootPart = Character.PrimaryPart

--[[VARIABLES]]--
local DASHCD = false
local DASHSPEED = 150

--[[FUNCTIONALITY]]--
--//Movement functions
local function DASH()
	if DASHCD then return end
	
	local WorldDir = Humanoid.MoveDirection
	if WorldDir.Magnitude <= 0.01 then return end
	DASHCD = true
	
	local LocalDir = RootPart.CFrame:VectorToWorldSpace(WorldDir)
	local F = LocalDir.Z   -- forward is negative Z in Roblox
	local R = LocalDir.X   -- right is +X

	
	local TH = 0.5
	local Dir
	if F <= -TH then Dir = "Forward"
	elseif F >= TH then Dir = "Backward"
	elseif R >= TH then Dir = "Right"
	elseif R <= -TH then Dir = "Left"
		else Dir = "Diagonal"
	end
	
	local DashVec = Vector3.new(R, 0, F).Unit * DASHSPEED
	RootPart.AssemblyLinearVelocity =  Vector3.new(DashVec.X, RootPart.AssemblyLinearVelocity.Y, DashVec.Z)
	
	task.delay(0.9, function() DASHCD = false end)
end

--//Binding
ContextActionService:BindAction("DASH", DASH, false, Enum.KeyCode.LeftControl)

Hey! The issue is likely that you’re converting Humanoid.MoveDirection unnecessarily. You can actually just use Humanoid.MoveDirection when setting your dash velocity as it already exists within the WorldSpace. In this case, you can replace your

local LocalDir = RootPart.CFrame:VectorToWorldSpace(WorldDir)
local F = LocalDir.Z   -- forward is negative Z in Roblox
local R = LocalDir.X   -- right is +X

with

local dash_vector = WorldDir.Unit * DASHSPEED
RootPart.AssemblyLinearVelocity = Vector3.new(dash_vector.X, RootPart.AssemblyLinearVelocity.Y, dash_vector.Z)

and get rid of the bottom

local DashVec = Vector3.new(R, 0, F).Unit * DASHSPEED
RootPart.AssemblyLinearVelocity =  Vector3.new(DashVec.X, RootPart.AssemblyLinearVelocity.Y, DashVec.Z)

It works! Though, I’m wondering how I can tell what direction the player is moving in since I’m planning to add animations and effects to it (specifically just forward, backwards, left, and right)?

You’d basically do the same thing you were doing with LocalDir before but instead of converting it into world space you’d convert it into object space

So LocalDir would equal RootPart.CFrame:VectorToObjectSpace(WorldDir) and then you’d just compare it like you did before.

if LocalDir.Z <= -TH then Dir = "Forward"
elseif LocalDir.Z >= TH then Dir = "Backward"
elseif LocalDir.X >= TH then Dir = "Right"
elseif LocalDir.X <= -TH then Dir = "Left"
      else Dir = "Diagonal" 
end

Then after that you’d implement the logic for animations, effects, etc. with the direction

Ah, alright then, thanks for the information!