Dash Script [HELP]

I have a dash script and I want it to play a different animation when using it while in the air, so if you jump it’s a dive instead of a roll. I tried to do it, didn’t work, so I’m gonna paste the original script and if anyone knows how to do this, and can add it, it’d be a massive help.

-- Get necessary services
local RS = game:GetService("ReplicatedStorage")
local VfxFolder = RS:WaitForChild("VfxFolder")
local DashClone = VfxFolder:WaitForChild("DashClone")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

-- Get the local player and their character
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()

-- Get references to the humanoid and the root part of the character
local Hum = Char:WaitForChild("Humanoid")
local HRP = Char:WaitForChild("HumanoidRootPart")

-- Variables to track key states
local WKeyDown = false
local AKeyDown = false
local SKeyDown = false
local DKeyDown = false

-- Variables to manage dashing
local DashDeb = false
local DashTime = 0.5

-- Load dash animations
local AnimationFolder = script:WaitForChild("AnimationFolder")
local ForwardDashAnime = Hum:LoadAnimation(AnimationFolder:WaitForChild("ForwardDash"))
local BackDashAnime = Hum:LoadAnimation(AnimationFolder:WaitForChild("BackDash"))
local LeftDashAnime = Hum:LoadAnimation(AnimationFolder:WaitForChild("LeftDash"))
local RightDashAnime = Hum:LoadAnimation(AnimationFolder:WaitForChild("RightDash"))

-- Event to signal dashing
local Event = script:WaitForChild("Event")

-- Handle input for dashing
UIS.InputBegan:Connect(function(Key, IsTyping)
	if IsTyping then return end
	if Key.KeyCode == Enum.KeyCode.Q then
		if DashDeb == false and Char:FindFirstChild("Deb") == nil then
			-- Set dash debounce
			DashDeb = true
			delay(DashTime + 2.5, function()
				DashDeb = false
			end)

			-- Dash forward
			if WKeyDown then
				coroutine.wrap(DashEffect)()
				local Tween = TweenService:Create(HRP, TweenInfo.new(DashTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Velocity = HRP.CFrame.LookVector * 100})
				Tween:Play()
				ForwardDashAnime:Play()
				Event:FireServer("Dash")
				delay(DashTime + 0.1, function()
					ForwardDashAnime:Stop()
				end)

				-- Dash left
			elseif AKeyDown then
				coroutine.wrap(DashEffect)()
				local Tween = TweenService:Create(HRP, TweenInfo.new(DashTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Velocity = HRP.CFrame.RightVector * -100})
				Tween:Play()
				LeftDashAnime:Play()
				Event:FireServer("Dash")
				delay(DashTime + 0.1, function()
					LeftDashAnime:Stop()
				end)

				-- Dash backward
			elseif SKeyDown then
				coroutine.wrap(DashEffect)()
				local Tween = TweenService:Create(HRP, TweenInfo.new(DashTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Velocity = HRP.CFrame.LookVector * -100})
				Tween:Play()
				BackDashAnime:Play()
				Event:FireServer("Dash")
				delay(DashTime + 0.1, function()
					BackDashAnime:Stop()
				end)

				-- Dash right
			elseif DKeyDown then
				coroutine.wrap(DashEffect)()
				local Tween = TweenService:Create(HRP, TweenInfo.new(DashTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Velocity = HRP.CFrame.RightVector * 100})
				Tween:Play()
				RightDashAnime:Play()
				Event:FireServer("Dash")
				delay(DashTime + 0.1, function()
					RightDashAnime:Stop()
				end)
			end
		end
	end
end)

-- Track key states
RunService.RenderStepped:Connect(function()
	WKeyDown = UIS:IsKeyDown(Enum.KeyCode.W)
	AKeyDown = UIS:IsKeyDown(Enum.KeyCode.A)
	SKeyDown = UIS:IsKeyDown(Enum.KeyCode.S)
	DKeyDown = UIS:IsKeyDown(Enum.KeyCode.D)
end)

-- Function to create dash effect
function DashEffect()
	for i = 1, 7 do
		local Clone = DashClone:Clone()
		Clone:SetPrimaryPartCFrame(HRP.CFrame)
		Clone.Parent = workspace
		game.Debris:AddItem(Clone, 0.5)

		spawn(function()
			for _, v in pairs(Clone:GetChildren()) do
				spawn(function()
					if v:IsA("MeshPart") or v:IsA("Part") then
						v.CFrame = Char:FindFirstChild(v.Name).CFrame
						for t = 0.25, 1, 0.1 do
							v.Transparency = t
							v.Reflectance = t
							wait()
						end
						Clone:Destroy()
					end
				end)
			end
		end)

		wait(0.05)
	end
end

local player = game.Players.LocalPlayer
local userInputService = game:GetService(“UserInputService”)

local speedIncrement = 10
local maxSpeed = 112 —CHANGE THIS TO THE SPEED YOU WANT YOUR MAXIMUM AT!!!
local baseSpeed = 16
local isBoosting = false
local humanoid

local function onKeyPress(input, gameProcessedEvent)
if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.Space then
isBoosting = true
while isBoosting and humanoid.WalkSpeed < maxSpeed do
humanoid.WalkSpeed = humanoid.WalkSpeed + speedIncrement
wait(1)
end
end
end

local function onKeyRelease(input)
if input.KeyCode == Enum.KeyCode.Space then
isBoosting = false
humanoid.WalkSpeed = baseSpeed
end
end

local function onCharacterAdded(character)
humanoid = character:WaitForChild(“Humanoid”)
userInputService.InputBegan:Connect(onKeyPress)
userInputService.InputEnded:Connect(onKeyRelease)
end

player.CharacterAdded:Connect(onCharacterAdded)

– Check if the character already exists (for cases where the player joins an existing game)
if player.Character then
onCharacterAdded(player.Character)
end

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