Animation of NPC's custom character is glitching

G’day people!
I’m making an survival game about postap and i need to make mutants for that. The mutants uses custom character, mesh that was rigged in blender and animated in roblox with pluging “Animation Editor”. When i put animation simply on character without walking script, that works perfectly:

But when i put it on NPC which is walking to me, animation is glitching:

  • If make animation constantly, so when NPC isnt walking the animation works good, but when NPC start move - animation broke.

Script for using animation

local h = script.Parent.Humanoid
local a = h:LoadAnimation(script:FindFirstChildOfClass("Animation"))

function isrun()
	--while script.Parent:FindFirstChild("Humanoid") ~= nil do
	if h.MoveDirection.Magnitude > 0 then
		a.Looped = true
		a:Play()
		end
		if	h.MoveDirection.Magnitude == 0 then
		a:Stop()
		end
	wait(3)
	--end
end
game:GetService("RunService").Heartbeat:Connect(isrun)

Hierarchy of character:
Desktop Screenshot 2022.12.27 - 13.32.26.80

Where is mistake? I tried to find topics with the same problem on devforum, yt or google, but i didnt found the same problem and all of the topics was about standart R6 or R15 character.
P.S. I’m ugly scripter so there would be problems, i’m sure.

It is a very simple problem, you read the script too much time so the animation play at the begining all the time here a simple code that will work I think :

local h = script.Parent.Humanoid
local a = h:LoadAnimation(script:FindFirstChildOfClass("Animation"))

h.Running:Connect(function(Speed)
	if Speed > 0 then
		a:Play()
	else
		a:Stop()
	end
end)

Have a nice day !

3 Likes

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