Making a dashing script [R6]

I am trying to make a script so the player dashes when they press Q, this works just how I want it, exept when you jump and then dash you fall, i want to make the player not fall until the dash is complete.

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")
local i = 0
local anims = {script.Dash1,script.Dash2}

local cooldown = false
local cooldowntime = 0.7
uis.InputBegan:Connect(function(key)
	if not cooldown then
		if key.KeyCode == Enum.KeyCode.Q then
			cooldown = true
			i = 1-i
			local playAnim = humanoid:LoadAnimation(anims[1+i])
			playAnim:Play()
			script.Sound:Play()
			if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
				player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 200
			else
				player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 130
			end
			wait(cooldowntime)
			cooldown = false
		end
	end
end)

(please ignore my bad code, this is what worked so i did it)

I guess you can anchor the HumanoidRootPart of your R6 Character and then unanchor it after the animations done playing.

You need this line of code to wait for your animation to finish:

playAnim.Ended:Wait()
1 Like

anchoring would stop the dash [character]

Are you sure you aren’t anchoring your whole character at this point? I am pretty sure your animation should keep playing if you only anchor the HumanoidRootPart. Maybe I could be wrong though. I never used R6 before.

1 Like

You can use a Align Position to lock the player to a position only on the Y-axis to stop them from falling while still moving.

-- Assumes 'hrp' is character's HumanoidRootPart
local attach = Instance.new("Attachment", hrp)

local alignPos = Instance.new("AlignPosition", hrp)
alignPos.Enabled = false -- Disabled on start
alignPos.Responsiveness = 50 -- set to your preference
alignPos.ApplyAtCenterOfMass = true
alignPos.ForceLimitMode = Enum.ForceLimitMode.PerAxis
alignPos.MaxAxesForce = Vector3.new(0, math.huge, 0) -- Only apply force on Y axis
alignPos.Mode = Enum.PositionAlignmentMode.OneAttachment
alignPos.Attachment0 = attach

For toggling:

-- Enabling
alignPos.Enabled = true
alignPos.Position = hrp.Position -- Update to current position

-- Disabling
alignPos.Enabled = false
2 Likes

Instead of directly setting the players velocity on the root part I would recommend using a body velocity or vector force to achieve the result you want. Even though body velocity is deprecated if you set the max force on the y-axis to something high and move the player with it they will not be affected by gravity until the force is removed.

1 Like

yeah but i want the player to move still which wont work when anchored

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