Dancing animations override other animations

I’ve tried to solve the problem by myself since i saw that in the last topic i posted almost nobody replied.

So as i said, i want to stop an animation when playing a different one, otherwise the two animation will override eachother and its required then to click on both animation buttons to stop them.
I’ve tried with Destroy() and with Humanoid:GetPlayingAnimationTracks , as @TheCarbyneUniverse told me but none of them worked in the way they’re supossed to (or in the way i want to).

After many tries and ways, i’ve reached this script which seems to look fine, without any errors but it wouldn’t work.

local waving = game.Players.LocalPlayer.PlayerGui.DancesGUI.MainFrame.ScrollingFrame.Waving.DanceButton.Emote
local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
	character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
local emote1 = hum:LoadAnimation(waving)
playing = false

script.Parent.MouseButton1Click:connect(function()
	if playing == false then
		emote1:Stop()
		emote:Play()
		hum.WalkSpeed = 0
		hum.JumpPower = 0
		playing = true
	elseif playing == true then
		emote:Stop()
		hum.WalkSpeed = 16
		hum.JumpPower = 50
		playing = false
	end
	emote1:Stop()
end)

The script above is located inside the button of the dance animation GUI, as shown below
image

The only difference between the two LocalScripts is that the first variable is defined on the other dance’s emote and the emote1:LoadAnimation(the first variable)

The two animations override eachother. If i click both of them and and then click one of them again, the unclicked animation will continue playing.
https://gyazo.com/b7735cb585d3a198a08f25c10c64d807

Thank you for helping :heart:

2 Likes

This is because you cannot destroy an animation track.
Did a quick test and

for i,v in pairs(Humanoid:GetPlayingAnimationTracks()) do
     v:Destroy()
end 

does not work. You need to use Track:Stop()

for i,v in pairs(Humanoid:GetPlayingAnimationTracks()) do
     v:Stop()
end 

I’m pretty sure this will solve your problem.

This can also be caused because your Animation Priority Was not set to Action.

@Luacrative
I have tried different ways to do this, including your for i,v in pairs and this is the one who seemed to do something, but now if i press anything my avatar freezes

local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
	character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
local playing = false

local Waving = game.Players.LocalPlayer.PlayerGui.DancesGUI.MainFrame.ScrollingFrame.Waving.DanceButton.Emote
local SoulSpin = game.Players.LocalPlayer.PlayerGui.DancesGUI.MainFrame.ScrollingFrame.SoulSpin.DanceButton.Emote

local dances = {
			Waving;
			SoulSpin
				}

script.Parent.MouseButton1Click:connect(function(Dance)
	if playing == false then
		emote:Play()
		playing = true
	elseif playing == true then
		emote:Stop()
		playing = false
	end
	for i,v in pairs(hum:GetPlayingAnimationTracks(dances)) do
     v:Stop()
end 
end)

https://gyazo.com/379ec3f3db7c50c5a7f3fc48884f6fbf

The Explorer layout is the same.

@Spentity All of the animations priorities are set to Action. I thought about that too and changed them all from Core to Action and reverse and got almost the same result. Only that if they’re on Core, if my avatar moves, the animations stops.