Animation will not play a second time

Hello, I have been looking for ages, I have found multiple other topics on this, and tried all of them, but none of them have been helpful, as the animation still only plays once.

Here is a video:

And here is my code:

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local humanoid = char:WaitForChild("Humanoid")
	
	char:SetAttribute("KatanaEquipped", false)

	local idle = humanoid:LoadAnimation(script.Idle)
	local running = humanoid:LoadAnimation(script.Running)
	
	local playingrun = false
	local playingidle = false
	local activated = false
	
	while wait() do
		local magnitude = humanoid.MoveDirection.Magnitude
		
		local speed = humanoid.WalkSpeed
		local equipped = char:GetAttribute("KatanaEquipped")
		
		if activated == true then
			if equipped == false then
				idle:Stop()
				running:Stop()
				activated = false
			end
		end
		
		local function main()
			if equipped == true then
				activated = true
				if magnitude <= 1 and magnitude > 0 then
					if speed > 16 then
						print("Sprinting")
					else
						if playingrun == false then
							playingrun = true
							playingidle = false
							idle:Stop()
							running:Play()
						end
					end
				end
				if magnitude == 0 then
					if playingidle == false then
						playingidle = true
						playingrun = false
						idle:Play()
						running:Stop()
					end
				end
			end
		end
		main()
	end
end)

How do I fix this annoying issue? Thanks for any help in advance.

3 Likes

I don’t see any issue in this video, could you highlight it better?

3 Likes

sorry,
when i unsheathe the katana, the animation plays and the player holds it to the right a little bit. when i sheathe and unsheathe it again, the player holds it forward. it also does it with walking.

and also the animation starts again when i move and go idle again.

1 Like

Check the animation priority, make sure no new animations are being played right after, and if there is, stop them or lower their weight.

3 Likes

the animations are both Action, I dont know if Action is the highest or Action4 is. they are both on loop too.

1 Like

Action highest, Action4 lowest.

3 Likes

thank you,
I really don’t know what is going on then, it just stops working the second time, I dont think there is any error in the code to unload the animation, I wouldnt really know

2 Likes

animationtrack:Stop() or animationtrack:Destroy() would stop it

2 Likes

would that unload it from the humanoid? i have it loaded from the start of the game when the player joins.

:Destroy() removes it and unloads it, :Stop() just stops but keeps it loaded.

2 Likes

i will try and mess around with prints to see where the code stops. thanks for your help

1 Like

You are welcome! 30 typing letter limit

2 Likes

i think i have just made a silly mistake, with the playingidle = true line in the magnitude == 0 part.

i never set the playingidle to false whenn unequipping, its all my fault lol. sorry for the time wasted.

1 Like

It’s ok, I’m in class and honestly I have nothing better to do.

oh right, well have fun in your class!

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