Animation not working!

I am coding a plugin and I have an animation, I know that the animation is owned by me and that it is not nil, any help?

for _, child in ipairs(children) do
					if child.ClassName == "ImageButton" then
						child.MouseButton1Click:Connect(function()
							if db2 == false then
								db2 = true
								local animationID = child.Main.AnimationID.AnimationId
								local animation = child.Main.AnimationID
								local viewport = mainzone.Preview.Main.ViewportFrame.WorldModel
								local char = viewport.Char
								local hum = char.Humanoid
								for i,v in pairs(hum:GetPlayingAnimationTracks()) do
									v:Stop()
								end
								local anim = hum:LoadAnimation(animation)
								anim:Play()
								anim.Looped = true
								PlayButton.Image = script.Parent.Images.Pause.Texture
								wait(1)
								db2 = false
							end
						end)
					end

Because you are not showing the entire script, I added some questions into your script and changed some stuff, read them:

for _, child in ipairs(children) do -- what is children? a table? or a folder/etc thing? if its not a table you need children:GetChildren()
	if child:IsA("ImageButton") then
		child.Activated:Connect(function()
			if db2 == false then -- debounce is false from start?
				db2 = true
				local animationID = child.Main.AnimationID.AnimationId
				local animation = child.Main.AnimationID
				local viewport = mainzone.Preview.Main.ViewportFrame.WorldModel
				local char = viewport.Char
				local hum = char.Humanoid
				for i,v in pairs(hum:GetPlayingAnimationTracks()) do
					v:Stop()
				end

				local anim = hum.Animator:LoadAnimation(animation) -- Load it into the Animator not Humanoid
				anim.Looped = true
				
				anim:Play()
				
				PlayButton.Image = script.Parent.Images.Pause.Texture -- PlayButton exist?
				task.wait(1)
				db2 = false
			end
		end)
	end
end

Are you loading the animation id? Shouldn’t you be loading the Animation instance?

Seems OP is loading the animation instance not the ID “seems”

local animation = child.Main.AnimationID
local anim = hum.Animator:LoadAnimation(animation)

well thats the code I changed, but I didnt touched that, so it seems its loading the proper instance not the ID

This is the ID, and that variable is not used in the entire script
local animationID = child.Main.AnimationID.AnimationId

1 Like

ok, from your code i already know:

  • your animation is in either startergui or PlayerGui
  • it’s probably a localscript, which is good to play animations

and all i want to say is the Animation instance shall be in workspace, or it wont work load (i’ve experienced these my self.)

2 Likes

im very sure you didn’t have to say “Seems”. because the property in Animation is AnimationId and not with a capital D. if the op did a typo the title would be “AnimationID is not a valid member of Animation” :sweat_smile:

1 Like

Im sure thats not true, I just tested it right now. I placed an animation instance inside the GUI, and by a local script I took that animation, loaded it into the Animator and Played it, and it works as expected.

If you experienced that, then you made a different mistake.

1 Like

What this means for you?

local animation = child.Main.AnimationID
local animationID = child.Main.AnimationID.AnimationId

It seems that AnimationID is an instance, and AnimationID.AnimationId is the property of that instance

1 Like

from that block of code, animation is an instance and animationID is the asset id, what’s wrong?

i’m not that stupid haha

1 Like

Something strange is going on, for some reason even though i know the animation gets through fine it just never plays

1 Like

Then yeah, OP loaded the instance not the id thats what I said, at least is what it seems:

local animation = child.Main.AnimationID
local anim = hum.Animator:LoadAnimation(animation)

but OP didnt use the Animator just the Humanoid

1 Like

Though deprecated using :loadanimation on a humanoid still works though not recommended, I did though fix this now

2 Likes

I’ve seen weird behavior when loading the animation into Humanoid before, thats why I always insist on load it into the Animator

2 Likes

Check if your animations priority is set to Core or Action
The animation wont appear to play if it is set to Core

On top of this, using :Connect() is finnicky, im pretty sure it will not Yield

Try this instead

child.MouseButton1Click:Wait()

(Also, check if the db boolean is set to true when you go through your if statements.)

1 Like

That did not work it just does not play the animation the click works

1 Like

Very sorry.

You need to provide the entire script as metioned here ^^^

2 Likes

Just for debugging your animation. Place this ScreenGui in your StarterGui, change the AnimationID of the Animation inside the GUI to yours and Play, read the output, it has warns/prints.

It should play your animation automatically after 4 seconds, if it doesnt work theres an issue with your Animation

A_Gui_With_Animation.rbxm (2.0 KB)

1 Like

I believe that they have no difference other than accessibility, its still good to change this ASAP, since this reference is deprecated.

2 Likes

You are probably right, that the only difference is accessibility, but Im pretty sure that I’ve seen a couple of posts in here where the animations were not running or moving its parts different than how those were designed, and by only changing the loading track from Humanoid to Animator the problem got solved.

Weird I have the same setup but for some reason it does not work on my plugin