Currently, I have a script that when you press shift it makes your walkspeed faster and it plays a animation, but the problem is that when I jump, it cancels out the sprint animation when I land, and it turns back into the normal walking animation. Here’s a visual representation.
I’m using custom animations, and the default roblox animation script
And this is the sprint script.
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
UserInputService.InputBegan:Connect(function(input, gameProccesed)
if gameProccesed then
return
else
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid = localPlayer.Character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 30
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://6828838446"
animation.Parent = humanoid
loadedAnimation = humanoid:LoadAnimation(animation)
loadedAnimation:Play()
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProccesed)
if gameProccesed then
return
else
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 16
loadedAnimation:Stop()
end
end
end)
After the character stops jumping and falls onto the ground, instead of resuming the run animation as normal it plays the walk animation although the character is still running
change the priorities of the animations around, make the run animation have a higher priority than the walk animation. You can change this when exporting the animation to roblox, its in the explorer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild('Humanoid')
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://507767714'
RAnimation = Humanoid:LoadAnimation(RunAnimation)
Running = false
function Handler(BindName, InputState)
if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then
Running = true
Humanoid.WalkSpeed = 50
elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then
Running = false
if RAnimation.IsPlaying then
RAnimation:Stop()
end
Humanoid.WalkSpeed = 16
end
end
Humanoid.Running:connect(function(Speed)
if Speed >= 10 and Running and not RAnimation.IsPlaying then
RAnimation:Play()
Humanoid.WalkSpeed = 50
elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
RAnimation:Stop()
Humanoid.WalkSpeed = 16
elseif Speed < 10 and RAnimation.IsPlaying then
RAnimation:Stop()
Humanoid.WalkSpeed = 16
end
end)
Humanoid.Changed:connect(function()
if Humanoid.Jump and RAnimation.IsPlaying then
RAnimation:Stop()
end
end)
game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)```