I’ve tried and failed miserably so I was wondering if anyone can / knows how to do this.
I have a script and whenever you press R the Player Rolls based on the key their holding. However, it works while the player is in the air. I was wondering if anyone knows how to make it so the rolling doesn’t activate on the ground, and; if it can work the same functionally but play a single, separate animation, that only goes forward. Which will be a dive:
StarterCharacterScripts:
LocalScript:
-- 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 Local Player and Character --
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
-- Get References to Humanoid and Root Part --
local Hum = Char:WaitForChild("Humanoid")
local HRP = Char:WaitForChild("HumanoidRootPart")
-- Track Key States --
local WKeyDown = false
local AKeyDown = false
local SKeyDown = false
local DKeyDown = false
-- 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 for 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.R then
if DashDeb == false and Char:FindFirstChild("Deb") == nil then
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 Continuously --
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)
-- 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
Child Script:
--- Getting the RemoteEvent --
local Event = script.Parent:WaitForChild("Event")
-- Handling RemoteEvent from the client --
Event.OnServerEvent:Connect(function(Player, Events)
-- Get character and humanoid root part --
local Char = Player.Character
local HRP = Char.HumanoidRootPart
-- Get the dash sound --
local Sound = script.Dash
-- Dash Event --
if Events == "Dash" then
-- Play the dash sound --
Sound:Play()
wait(0.8)
-- Stop the dash sound --
Sound:Stop()
end
end)
Thank you!