Why does this animation loop?

ok. i’ve been working on a sprint script recently and after implementing some stamina stuff, this bug was present before but it got even more noticable. whenever i jump, the fall animation is supposed to play, it does, but then it constantly replays even though it’s not set on loop in the animation maker.

could i get some help? here is the script:

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Stamina = 100
local Running = false

Stamina = math.clamp(Stamina, 0, 100)

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Running = true
		Character.Humanoid.WalkSpeed = 24
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://7384132764'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
		while Stamina > 0 and Running do
			Stamina = Stamina - 1
			script.Parent:TweenSize(UDim2.new(Stamina/ 100, 0, 1, 0), "Out", "Linear",0)
			wait(0.06)
			if Stamina == 0 then
				Character.Humanoid.WalkSpeed = 16
				PlayAnim:Stop()

			end
		end
	end
if input.KeyCode == Enum.KeyCode.Space then
local JumpAnim = Instance.new('Animation')
local FallAnim = Instance.new('Animation')
JumpAnim.AnimationId = 'rbxassetid://7391963123'
FallAnim.AnimationId = 'rbxassetid://7397288802'
FallAnimPlay = Character.Humanoid:LoadAnimation(FallAnim)
JumpAnimPlay = Character.Humanoid:LoadAnimation(JumpAnim)
PlayAnim:Stop()
JumpAnimPlay:Play()
	while Stamina > 0 and Running do
wait(0.06)
		if Stamina == 0 then
			Character.Humanoid.WalkSpeed = 16
			JumpAnimPlay:Stop()
			FallAnimPlay:Stop()
		end
	end
end

	if (JumpAnimPlay) then
		wait(JumpAnimPlay.Length)
		FallAnimPlay:Play()
		wait(FallAnimPlay.Length)
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Running = false
		Character.Humanoid.WalkSpeed = 16
		PlayAnim:Stop()
	end
	if input.KeyCode == Enum.KeyCode.Space then
		JumpAnimPlay:Stop()
		FallAnimPlay:Stop()
		PlayAnim:Play()
	end
	while Stamina < 100 and not Running do
		Stamina = Stamina + 1
		script.Parent:TweenSize(UDim2.new(Stamina/ 100, 0, 1, 0), "Out", "Linear",0)
		wait(0.06)
		if Stamina == 0 then
			Character.Humanoid.WalkSpeed = 16
			PlayAnim:Stop()
		end
	end
end)

here is a video of what happens:

https://i.gyazo.com/2c55384ae356423f298e439433dfbd91.mp4

hope it helps! thank you for reading this!

1 Like

I don’t think this is a code issue. When exporting your animation, if you set the animation to loop in the animation editor, it will also loop within your game.

2 Likes

That is not your code. You should edit the animation and disable looping. Then export it again.

2 Likes

put “animation.Looped = false” somewhere before you play the animation. That should fix the issue. This could also be fixed by doing what @skillednames and @Davide_24 said, but this is just another way to fix it.

Opposite bool value if you want an animation to loop, but it is not normally. ( animation.Looped = true )

4 Likes

You don’t have any proof that it isn’t his code or not

1 Like

Hes telling the truth this happened to me And i was very annoyed at roblox for not taking the time to make me realize this

ive had this problem dont worry its most likely that he put the loop animations all he has to do is import the animation and unloop the animation and export its

I meant that the error is not in his code.