I am using animation events to yield for a loop but the animation ends too early causing the whole script to break, any workarounds?
task.spawn(function()
AnimationMORPH.Ended:Wait()
print("ended")
Character:FindFirstChild("HumanoidRootPart").Anchored = false
end)
for _,v in Player.Character:GetChildren() do
if v.Name == "HumanoidRootPart" or not v:IsA("BasePart") then continue end
local P = ChangePart(v)
if v.Name == "Head" then
v.Transparency = 0
v.face:Destroy()
else
AnimationMORPH:GetMarkerReachedSignal("TR"):Wait()
v.Transparency = 1
end
table.insert(CleanUp, v)
AnimationMORPH:GetMarkerReachedSignal("TR"):Wait()
print("TR ENDED")
end
The workarounds i found for me may not work for you, but i extended the animation out like a milisecond and then would use markerreached because then if it was late the animation would not reset. It probably wont work like that for you though.
local AnimationMORPH = -- replace with your animation
local Player = game.Players.LocalPlayer
local function HandlePart(part)
if part.Name == "Head" then
part.Transparency = 0
if part:FindFirstChild("face") then
part.face:Destroy()
end
else
AnimationMORPH:GetMarkerReachedSignal("TR"):Wait()
part.Transparency = 1
end
table.insert(CleanUp, part)
end
local CleanUp = {}
AnimationMORPH.Ended:Wait()
print("Animation ended")
Player.Character:WaitForChild("HumanoidRootPart").Anchored = false
for _, part in ipairs(Player.Character:GetChildren()) do
if part.Name == "HumanoidRootPart" or not part:IsA("BasePart") then
continue
end
ChangePart(part)
HandlePart(part)
AnimationMORPH:GetMarkerReachedSignal("TR"):Wait()
print("TR ENDED")
end