I’ve got a spawning animation for my monster and I have to wait for it to load. As you can see, I’ve got some code that attempts to wait for it to load, but sometimes the animation loads and plays and sometimes it doesn’t play at all. How can I fix this?
Code -
local exitPortal = humanoid.Animator:LoadAnimation(monster.Animations.ExitPortal)
while exitPortal.Length == 0 do task.wait() end
task.wait()
exitPortal:Play(0)
wait(0.05)
monster.HumanoidRootPart.CFrame = assets:FindFirstChild("Map")["Monster Spawn"].CFrame + Vector3.new(0, humanoid.HipHeight, 0)
exitPortal.Stopped:Wait()
humanoid.JumpPower = 40
humanoid.WalkSpeed = walkSpeed
if monster:FindFirstChild("AI") then
monster["AI"].Disabled = false
end
local color = characterList[monster.OrgName.Value].Color:ToHex()
module.sendGameEvent([[<font color="#]].. color ..[["><stroke color="#]].. color ..[[">]].. monster.OrgName.Value ..[[</stroke></font> is coming...]])
Try using Animation:IsLoaded()
It returns a boolean value that tells if the client has finished loading the animation.
Maybe that would help?
I’m not sure if it will work though.
So, you load the animation onto the humanoid, and then repeat waiting until its length is greater than 0. This works very well. I use it on all my games.
local Anim = humanoid:LoadAnimation(animation)
repeat wait() until Anim.Length > 0
Im still new to animating, and i much prefer scripting. I barely look into animations, but loading them onto a humanoid works.
Ive never heard of loading animations onto the animator.
Okay so, I would prefer using the Track’s length (don’t wrap it in a while loop, use something like repeat) or by waiting the time of the animation to load, which is around 0.5 seconds per animation in ROBLOX.
I worked on my custom animation player which is here. You might find it useful? you can just play the animation literally once. Might not be most optimized way of doing stuff I have no idea…
Use AnimationTrack:IsPlaying and task.wait and repeat and disconnect stuff
replace
to
local exitPortal = humanoid.Animator:LoadAnimation(monster.Animations.ExitPortal)
local animationLoaded = false
local connection = exitPortal:GetPropertyChangedSignal("IsPlaying"):Connect(function()
if exitPortal.IsPlaying then
animationLoaded = true
end
end)
repeat task.wait() until animationLoaded
connection:Disconnect()
That worked! Thanks, here’s the updated code if you wanna see!
task.spawn(function()
local exitPortal = humanoid.Animator:LoadAnimation(monster.Animations.ExitPortal)
monster.Animate.Disabled = true
for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
for i, v in pairs(monster.HumanoidRootPart:GetChildren()) do
if v:IsA("Sound") then
v:Stop()
end
end
repeat task.wait() until exitPortal.Length > 0
exitPortal:Play(0)
repeat task.wait() until exitPortal.IsPlaying
task.wait(0.1)
monster.HumanoidRootPart.CFrame = assets:FindFirstChild("Map")["Monster Spawn"].CFrame + Vector3.new(0, humanoid.HipHeight, 0)
exitPortal.Stopped:Wait()
humanoid.JumpPower = 40
humanoid.WalkSpeed = walkSpeed
monster.Animate.Disabled = false
if monster:FindFirstChild("AI") then
monster["AI"].Disabled = false
end
local color = characterList[monster.OrgName.Value].Color:ToHex()
module.sendGameEvent([[<font color="#]].. color ..[["><stroke color="#]].. color ..[[">]].. monster.OrgName.Value ..[[</stroke></font> is coming...]])