Stop Anim from overlapping?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Stop the animations from playing if another anim is also played.

  2. What is the issue? Include screenshots / videos if possible!
    Animations overlap.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried to make a script that would stop any other anim if played, but that went horribly wrong.

Heres are the scripts:

Griddy/Pigeon Button
Griddy is a Core priority as it was animated using live animation.
Pigeon is an Action1 Priority

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local playing = false
local anim = script:FindFirstChild("Animation")
local button = script.Parent
local lod = char:WaitForChild("Humanoid"):LoadAnimation(anim)

button.MouseButton1Click:Connect(function()
	if playing == false then
		playing = true
		lod:Play()
		script.Sound:Play()
		char.Humanoid.WalkSpeed = 5
	else
		script.Sound:Stop()
		char.Humanoid.WalkSpeed = 16
		playing = false
		lod:Stop()
	end
end)

Little Brother/Kneeslide Button
Little Brother is Action Priority
Kneeslide is Movement Priority

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local playing = false
local anim = script:FindFirstChild("Animation")
local button = script.Parent
local lod = char:WaitForChild("Humanoid"):LoadAnimation(anim)

button.MouseButton1Click:Connect(function()
	if playing == false then
		playing = true
		lod:Play()
	else
		playing = false
		lod:Stop()
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Use this to get what animations are playing on a humanoid:

local animtracks = humanoid:GetPlayingAnimationTracks()
1 Like

This works, but would there be any way for the audios to stop aswell?

1 Like

Just use sound:Stop(), and then delete it with sound:Destroy(). I would put the sound in the Humanoid so you can locate it easily.

1 Like

I tried using animtracks:Stop() Did i do something wrong? The output printed:

attempt to call missing method 'Stop' of table
1 Like

It returns a table. Use a forloop to stop all animations.

2 Likes

you need to do a for loop

local animtracks = humanoid:GetPlayingAnimationTracks()

for _, animation in pairs(animtracks) do
    animation:Stop()
end
2 Likes

Ah, i see. Im just starting to learn for loops, so i dont understand them completely.

1 Like

animtracks returns a table so this is why you need to use a for loop because you need to read every element of the returned table

Oh so basically the “animation” are the elements inside of Animtracks?

1 Like

basically yeah that’s it. and the _ stands for the index which is the location of the animation in the table but as we don’t need it in our code we use _ instead of using a variable name. Tell me if I’m not clear

I didnt really understand what you mean when you said Location of anim in the table :sweat_smile:

it’s okay, for example a table could look like this :

{"dog", "cat", "boar", "pig"}

and here for example, the location of “dog” is 1 so the index of “dog” is 1. And “cat” index is 2 etc

Oh now i understand, so basically Index is kinda like the amount of elements in a table?

it’s the location of an element in your table base on its position in the table, you should watch some videos about these to get it clear

1 Like

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