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
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”
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.
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
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.