so, my animation script checks for when a certain object has been intruduced into the workspace. Problem is, when they get destroyed, the animation script errors out Infinite yield possible with JumpyZombie:WaitForChild("Humanoid"). I know the problem, just not the solution.
heres my script.
workspace.Mobs.ChildAdded:Connect(function(object)
if object.Name == "JumpyZombie" then
wait(5.5)
playAnimation(object, "Jump")
end
end)
local function setAnimation(object, animName)
local hum = object:WaitForChild("Humanoid")
local animFolder = object:WaitForChild("Animations")
if hum and animFolder then
local animObject = animFolder:WaitForChild(animName)
if animObject then
local animator = hum:FindFirstChild("Animator")
local playingTracks = animator:GetPlayingAnimationTracks()
for i, track in pairs(playingTracks) do
if track.name == animName then
return track
end
end
local animTrack = animator:LoadAnimation(animObject)
return animTrack
end
end
end
Does it print anything or errors in the output? If not then try debugging the script and print out humanoid, animation folder and the animator object, if one of them is nil then the object was created after the script execution
Is this where it warned? Then change this line below back to WaitForChild to see whether it works or not. If it says Infinite yield possible then it doesn’t actually exist, check the animFolder
Wait, where are the animations created, on server or client? And is the script a server or local script? It might not show for the server if it is created locally. If it’s not then I have no idea honestly.
Can you send a reproduction file that contains all of the objects related to the problem? If we continue to fix this without my knowledge of the structure it will take forever to solve (sorry if this bothers you)
Open a new baseplate, then copy everything to the baseplate that is used by the script (in their exact location in the game, if there is something sensitive you can replace it with a new part of the same class, and you can delete the animation ids loaded). Try to include as little objects as possible that can still reproduce the error and in their correct locations used in your game
Hope I helped!
I tested this and it somehow works completely fine. I used this script, which is not very different from the one you provided:
local function setAnimation(object, animName)
local hum = object:FindFirstChild("Humanoid")
local animFolder = object:FindFirstChild("Animations")
if hum and animFolder then
local animObject = animFolder:FindFirstChild(animName)
if animObject then
local animator = hum:WaitForChild("Animator")
local playingTracks = animator:GetPlayingAnimationTracks()
for i, track in pairs(playingTracks) do
if track.name == animName then
return track
end
end
local animTrack = animator:LoadAnimation(animObject)
animTrack.Looped = true
print(animTrack)
print(animator:GetPlayingAnimationTracks())
return animTrack
else warn("no anim object?")
end
else warn("no hum?")
end
end
local function playAnimation(object, animName)
local anim = setAnimation(object, animName)
print("animation retrieved")
anim:Play()
print(object.Humanoid.Animator:GetPlayingAnimationTracks())
end
workspace.Mobs.ChildAdded:Connect(function(object)
print("add")
if object.Name == "JumpyZombie" then
while true do
wait(5.5)
playAnimation(object, "Jump")
print("success")
end
end
end)
Here is the output for this code:
10:21:44.876 Jump - Server - Script:20
10:21:44.881 {} - Server - Script:21
10:21:44.881 animation retrieved - Server - Script:31
10:21:44.881 â–Ľ {
[1] = Jump
} - Server - Script:33
10:21:44.882 success - Server - Script:42
Try checking if the animation is r15 or r6, and if the rig is anchored. There’s nothing wrong with it currently.