my problem is that my animations are causing like a freezing effect on my NPC between animations. it only seems to happen when i just load in the game and after a while the animations become smooth, just the way i want it. i’m not sure what the problem is but i appreciate any help.
video highlighting the problem:
animation.AnimationId = "http://www.roblox.com/asset/?id="..animationIDTable["FriendlyRunAnim"]
animTrack = somedudeAnimator:LoadAnimation(animation)
animTrack:Play()
local function onHumanoidDied()
if connection then
connection:Disconnect()
end
end
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
local playerHumanoid:Humanoid = c:WaitForChild("Humanoid")
local hurley:Tool = somedudethatfollowsu:FindFirstChild("hurley")
if hurley then
somedudethatfollowsuHumanoid:EquipTool(hurley)
end
playerHumanoid.Died:Connect(onHumanoidDied)
-- Disconnect any existing connection before creating a new one
if connection then
connection:Disconnect()
end
connection = RS.Heartbeat:Connect(function()
local mag = (somedudethatfollowsu:WaitForChild("HumanoidRootPart").Position - c:WaitForChild("HumanoidRootPart").Position).Magnitude
somedudethatfollowsuHumanoid:MoveTo(c:WaitForChild("HumanoidRootPart").Position)
if mag < 20 then
if animation then
if not isAnimating then
isAnimating = true
-- Start RaiseHurleyAnim
if animTrack then
animTrack:Stop()
animTrack = nil
end
animation.AnimationId = "http://www.roblox.com/asset/?id="..animationIDTable["RaiseHurleyAnim"]
animTrack = somedudethatfollowsuHumanoid.Animator:LoadAnimation(animation)
animTrack:Play()
animTrack:GetMarkerReachedSignal("startNextAnimation"):Connect(function()
--Transition to AggressiveRunAnim
if not isTransitioning then
isTransitioning = true
animTrack:Stop()
animation.AnimationId = "http://www.roblox.com/asset/?id="..animationIDTable["AggressiveRunAnim"]
animTrack = somedudethatfollowsuHumanoid.Animator:LoadAnimation(animation)
animTrack:Play()
animTrack.Ended:Connect(function()
isAnimating = false
isTransitioning = false
end)
end
end)
end
end
elseif mag >= 20 then
if animTrack and animTrack.IsPlaying then
animTrack:GetMarkerReachedSignal("startFriendlyAnimation"):Connect(function()
animTrack:Stop()
animation.AnimationId = "http://www.roblox.com/asset/?id="..animationIDTable["LowerHurleyAnim"]
animTrack = somedudethatfollowsuHumanoid.Animator:LoadAnimation(animation)
animTrack:Play()
animTrack:GetMarkerReachedSignal("startFriendlyRun"):Connect(function()
animTrack:Stop()
animation.AnimationId = "http://www.roblox.com/asset/?id="..animationIDTable["FriendlyRunAnim"]
animTrack = somedudethatfollowsuHumanoid.Animator:LoadAnimation(animation)
animTrack:Play()
end)
isAnimating = false
end)
end
end
end) -- End of RS.Heartbeat:Connect
end) -- End of p.CharacterAdded:Connect
end) -- End of game.Players.PlayerAdded:Connect