Dashing flings the player when smashing space

Hello everyone i have this simple script right here wich is a dash system but i found out if we dashed backwards without jumping before and smash the space bar it will just fling the player

Here’s what i mean :

Here’s the script :

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local huamnoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local replicatedStorage = game:GetService("ReplicatedStorage")
local cooldownBindableEvent = replicatedStorage.CooldownEvents:WaitForChild("Cooldown")

local forwardDash = huamnoid:LoadAnimation(script:WaitForChild("ForwardDash"))
local backwardDash = huamnoid:LoadAnimation(script:WaitForChild("BackwardDash"))
local leftDash = huamnoid:LoadAnimation(script:WaitForChild("LeftDash"))
local rightDash = huamnoid:LoadAnimation(script:WaitForChild("RightDash"))

local Debris = game:GetService("Debris")

local UIS = game:GetService("UserInputService")

local debounce = false

UIS.InputBegan:Connect(function(input,gpe)
	if gpe then return end

	if input.KeyCode == Enum.KeyCode.C and player:GetAttribute("isStunned") == false and player:GetAttribute("isBlocking") == false and player:GetAttribute("isAttacking") == false and debounce == false then
		debounce = true
		local linearVelocity = Instance.new("LinearVelocity",humanoidRootPart)
		linearVelocity.Attachment0 = humanoidRootPart:WaitForChild("RootAttachment")
		linearVelocity.MaxForce = math.huge
		if UIS:IsKeyDown(Enum.KeyCode.W) then
			forwardDash:Play()
			linearVelocity.VectorVelocity = humanoidRootPart.CFrame.LookVector.Unit * 50
		elseif UIS:IsKeyDown(Enum.KeyCode.S) then
			backwardDash:Play()
			linearVelocity.VectorVelocity = humanoidRootPart.CFrame.LookVector.Unit * -50
		elseif UIS:IsKeyDown(Enum.KeyCode.D) then
			leftDash:Play()
			linearVelocity.VectorVelocity = humanoidRootPart.CFrame.RightVector.Unit * 50
		elseif UIS:IsKeyDown(Enum.KeyCode.A) then
			rightDash:Play()
			linearVelocity.VectorVelocity = humanoidRootPart.CFrame.RightVector.Unit * -50
		end
		
		cooldownBindableEvent:Fire("Dash",2)
		
		Debris:AddItem(linearVelocity,.3)
		task.wait(2)
		debounce = false
	end
end)

can u show how its working without the bug

and is your linear velocity relativoto world or attachment

Sure thing sorry i was afk also the attachement is relative to world

I can’t make a long video idk how to do that :confused:

Probably something wrong with your jump mechanic, or maybe because you’re using math.huge for the MaxForce.

I fond out why it does this it’s because i have a script that tilts the character forward , backward left and right when i disable it the dash works correctly

Here’s the script i mentioned :

local dir, vel
local angle = 0
local angle2 = 0

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local root = char:WaitForChild("HumanoidRootPart")
local Joint = root:WaitForChild("RootJoint")
local LeftLegJoint = Joint.Part1:WaitForChild("Left Hip")
local RightLegJoint = Joint.Part1:WaitForChild("Right Hip")
local OriginalPos = Joint.C0
local OriginalLeftlLegPos = LeftLegJoint.C0
local OriginalRightLegPos = RightLegJoint.C0

local DevideAngle = 5
local DevideAngle2 = 5
local TiltSpeed = .3

game:GetService("RunService").Heartbeat:Connect(function()
	vel = root.Velocity * Vector3.new(1,0,1)
	if vel.Magnitude > 2 then
		dir = vel.Unit
		angle = root.CFrame.RightVector:Dot(dir) / DevideAngle
		angle2 = root.CFrame.LookVector:Dot(dir) / DevideAngle2
	else
		angle = 0
		angle2 = 0
	end

	Joint.C0 = Joint.C0:Lerp(OriginalPos * CFrame.Angles(angle2, -angle, 0),TiltSpeed)   
end)

Found the solution i just used BodyVelocity and set the maxForce to Vector3.new(math.huge,0,math.huge) afaik i don’t know if we can stop applying force to the y axis using linearVelocity

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