I am making NPCs that dance randomly and repeatedly. But they sometimes get stuck. I don’t know why this is happening. How can i fix it? Here’s the code.
local humanoid = script.Parent:WaitForChild("Humanoid")
local ContentProvider = game:GetService("ContentProvider")
script.Parent.PrimaryPart:SetNetworkOwner(nil)
local animationIds = {
"http://www.roblox.com/asset/?id=3333499508", -- Monky
"http://www.roblox.com/asset/?id=5937560570", -- old
"http://www.roblox.com/asset/?id=3333136415", -- side
"http://www.roblox.com/asset/?id=4212455378", -- dorky
"http://www.roblox.com/asset/?id=5918726674", -- dolphin
"http://www.roblox.com/asset/?id=5915648917", -- break
"http://www.roblox.com/asset/?id=5915648917", -- break
"http://www.roblox.com/asset/?id=5915648917", -- break
"http://www.roblox.com/asset/?id=5917459365", -- floss
"http://www.roblox.com/asset/?id=5937558680", -- holiday
"http://www.roblox.com/asset/?id=6797888062", -- hips
"http://www.roblox.com/asset/?id=5918728267", -- rodeo
"http://www.roblox.com/asset/?id=3338025566", -- robot
"http://www.roblox.com/asset/?id=7198989668", -- show
"http://www.roblox.com/asset/?id=7465981288", -- quiet
"http://www.roblox.com/asset/?id=3333432454", -- fancy
"http://www.roblox.com/asset/?id=6797890377", -- take
"http://www.roblox.com/asset/?id=5915713518", -- panini
"http://www.roblox.com/asset/?id=6797891807", -- it
"http://www.roblox.com/asset/?id=7404878500", -- dancin
"http://www.roblox.com/asset/?id=7422779536", -- on
"http://www.roblox.com/asset/?id=7942896991", -- lasso
"http://www.roblox.com/asset/?id=7199000883", -- wake
"http://www.roblox.com/asset/?id=4049037604", -- line
"http://www.roblox.com/asset/?id=4265725525", -- baby
"http://www.roblox.com/asset/?id=3361276673", -- top
"http://www.roblox.com/asset/?id=3303391864", -- around
"http://www.roblox.com/asset/?id=7942885103", -- aok
"http://www.roblox.com/asset/?id=7422807549", -- saturday
"http://www.roblox.com/asset/?id=4101966434", -- idol
"http://www.roblox.com/asset/?id=7465946930", -- flowing
}
local animations = {}
for i, animationId in pairs(animationIds) do
local animation = Instance.new("Animation")
animation.AnimationId = animationId
table.insert(animations, i, animation)
end
ContentProvider:PreloadAsync(animations)
while wait() do
local animation = humanoid:LoadAnimation(animations[math.random(#animations)])
animation.TimePosition = 0
animation.Looped = false
animation:Play()
animation.didLoop:Wait(animation.Length)
end