Problem on Dash script

I’m trying to make, for the first time, a four directional dash
But it’s not working like I wanted.

For some reason the dash works at front/back but not at left/right and the dash speed gets lower when touching the ground

I tried to find some solutions on internet, here on devforum (searching) and with ChatGPT, and nothing helped that much

Here’s the script:

game.ReplicatedStorage.Events.ClientEvents.Dash.OnServerEvent:Connect(function(plr)
	
	local char = plr.Character
	
	local dir = char.HumanoidRootPart.Velocity:Dot(char.HumanoidRootPart.CFrame.LookVector)
		
	if dir > 0.9 then
			
		local anim = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Normal.Dash.Front)
		anim:Play()
			
		local vectormove = Instance.new("VectorForce", char.HumanoidRootPart)
		vectormove.Attachment0 = char.HumanoidRootPart.RootAttachment
		vectormove.Force = Vector3.new(0,2000,-13000)
		wait(0.1)
		vectormove:Destroy()
			
	elseif dir < 0.9 then

		local anim = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Normal.Dash.Back)
		anim:Play()
		
		local vectormove = Instance.new("VectorForce", char.HumanoidRootPart)
		vectormove.Attachment0 = char.HumanoidRootPart.RootAttachment
		vectormove.Force = Vector3.new(0,2000,13000)
		wait(0.1)
		vectormove:Destroy()
		
	else
		
		dir = char.HumanoidRootPart.Velocity
		dir = dir.Unit

		if math.abs(dir.X) > math.abs(dir.Z) then

			if dir.X > 0 then

				local anim = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Normal.Dash.Right)
				anim:Play()

				local vectormove = Instance.new("VectorForce", char.HumanoidRootPart)
				vectormove.Attachment0 = char.HumanoidRootPart.RootAttachment
				vectormove.Force = Vector3.new(-13000,2000,0)
				wait(0.1)
				vectormove:Destroy()

			else

				local anim = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Normal.Dash.Left)
				anim:Play()

				local vectormove = Instance.new("VectorForce", char.HumanoidRootPart)
				vectormove.Attachment0 = char.HumanoidRootPart.RootAttachment
				vectormove.Force = Vector3.new(13000,2000,0)
				wait(0.1)
				vectormove:Destroy()

			end

		end
		
	end
	
end)

I made this a while back for my dashing

local ControlModule = require(Player:WaitForChild("PlayerScripts").PlayerModule:WaitForChild("ControlModule"))

local function detectMovementDirection(Vector)
	local CurrentKey = "None"
	
	if Vector == Vector3.new(0, 0, 0) then
		CurrentKey = "None"
	elseif Vector.z >= -1 and Vector.z < 0 then
		CurrentKey = "W"
	elseif Vector.z > 0 then
		CurrentKey = "S"
	elseif Vector.x >= -1 and Vector.x < 0 then
		CurrentKey = "A"
	elseif Vector.x > 0 then
		CurrentKey = "D"
	end

	return CurrentKey
end




local function GetHeldKey()
	local CurrentKey = "None"
	local MoveVector = ControlModule:GetMoveVector()

	CurrentKey = detectMovementDirection(MoveVector)

	return CurrentKey
end




So what you can do is
if GetHeldKey() == “W” then do the Vector for w and so on

1 Like

Sorry about just replying now.

It worked well! Just made my local script of key detecting start your function and giving the result to the event and after remaking a little of the script all worked fine! Thanks!

1 Like

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