I have a shift to sprint script and I put an animation there but if I start running then it stops like 0.2 seconds after and if I turn around it also stops too. How do I fix this?
Script:
local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild(‘Humanoid’)
local RunAnimation = Instance.new(‘Animation’)
RunAnimation.AnimationId = ‘rbxassetid://8071883568’
RAnimation = Humanoid:LoadAnimation(RunAnimation)
Running = false
function Handler(BindName, InputState)
if InputState == Enum.UserInputState.Begin and BindName == ‘RunBind’ then
Running = true
Humanoid.WalkSpeed = 48
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 = 48
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)
I don’t think there’s anything necessarily wrong with your code. I think what’s happening is that once your run animations goes through a full cycle, it stops. This is because animations are meant to play once by default and not play again until triggered. You can combat this by simply setting the Looped value of your AnimationTrack to true, like this:
RAnimation.Looped = true -- line 8 (right after your RAnimation variable declaration)
Also, the way you’re retrieving the character from the character is a risky way of achieving this. What happens if a part in your workspace happens to have the same name as your player? I suggest you replace line 2 with the following code.
repeat wait() until Player.Character
local Character = Player.Character
Hope this helps. Let me know if you have any issues or further questions.
I did and that is what the animation is supposed to look like. But instead it starts for a tiny bit and ends right after like I showed on the other vids. yes the animation is a free model cuz i suck at animating but it was looped when i loaded it in.