How to fix NPC having no animation for 1-2 second

Question is in title

I’ve been searching solution for 3 days and still didnt find it yet
Most likely this might be cuz of delay between Play() and Stop() but i’m not sure

I tried to replace them, still not working properly as i wanted.

Script:

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local RootPart = Character:WaitForChild("HumanoidRootPart")

local ContentProvider = game:GetService("ContentProvider")

local idleAnim = Animator:LoadAnimation(script.Idle)
local walkAnim = Animator:LoadAnimation(script.Walk)

idleAnim.Priority = Enum.AnimationPriority.Idle
walkAnim.Priority = Enum.AnimationPriority.Movement

local walking = false
idleAnim:Play()

Humanoid.Running:Connect(function(speed)
	if speed >= 1 and not walking and not walkAnim.IsPlaying and idleAnim.IsPlaying then
		walkAnim:Play()
		idleAnim:Stop()
		walking = true
	elseif speed < 1 and walking then
		walkAnim:Stop()
		idleAnim:Play()
		walking = false
	elseif speed < 1 and walking and walkAnim.IsPlaying then
		walkAnim:Stop()
		idleAnim:Play()
		walking = false
	end
end)

script is big so i put here only animations part of it

Pretty sure it is the >= 1 speed, as it takes some time for the character to accelerate. I can’t really fact check this as I’m on mobile, but based on the times I’ve used Humanoid.Running the speed takes a little. Change the 1 to a lower number.

I tried that, didnt fix the problem still
I’m pretty sure that is happening cuz walking animation playing for first time so it delays little bit
I even tried to preload animations but still…

Maybe try repeating walkAnim:Play() until it isPlaying

Check by printing something next to the line where the animation plays so that you know if the animation is delaying or the Humanoid.Running is causing it. (You might have done this already I just don’t know)

This didnt work BUT you made me think what if i delay stopping idle animation AND IT WORKED
basically there was delay between stoping idle anim and playing walk animation.

Humanoid.Running:Connect(function(speed)
	if speed >= 1 and not walking and not walkAnim.IsPlaying and idleAnim.IsPlaying then
		walkAnim:Play()
		--idleAnim:Stop()
		walking = true
	elseif speed < 1 and walking then
		walkAnim:Stop()
		idleAnim:Play()
		walking = false
	elseif speed < 1 and walking and walkAnim.IsPlaying then
		walkAnim:Stop()
		idleAnim:Play()
		walking = false
	end
end)

Tho i dont really know is that bad if i play some Animation over other one even with higher priority, might cause bugs in future, ill edit my comment if something like that happen.

Thanks yall

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.