Pathfinding Walking Animation Bug

I am currently working on a Pathfinding system where an entity chases you and when your close it enough it kills you. Everything is going well except the walking animation sometimes bugs out when it’s chasing you, any ideas?

Script:

--Services--
local RunService = game:GetService('RunService')
local PathfindingService = game:GetService('PathfindingService')

--Variable--
local hum = script.Parent.Humanoid
local humrp = script.Parent.HumanoidRootPart
local Animator = hum.Animator

--Pathfinding
script.Parent.PrimaryPart:SetNetworkOwner(nil)
local destination = workspace.Part.Position

local function findTarget()
	local players = game.Players:GetPlayers()
	local MaxDistance = 40
	local nearestTarget
	
	for i,v in pairs(players) do
		if (v.Character) then
			local target = v.Character
			local distance = (humrp.Position - target.HumanoidRootPart.Position).Magnitude
			
			if (distance < MaxDistance) then
				nearestTarget = target
				MaxDistance = distance
			end
		end
	end
	
	return nearestTarget
end

local function agro(target)
	local distance = (humrp.Position - target.HumanoidRootPart.Position).Magnitude
	
	if (distance > 8) then
		hum:MoveTo(target.HumanoidRootPart.Position)
	else
		target.Humanoid.Health = 0
	end
end

local function createPath(destination)
	local path = PathfindingService:CreatePath()
	path:ComputeAsync(humrp.Position, destination)
	
	return path
end

local function walkTo(destination)
	local path = createPath(destination)
	
	local waypoints = path:GetWaypoints()

	for i,v in pairs(waypoints) do
		local target = findTarget()
		
		if (target) then
			agro(target)
			break
		end
		
		hum:MoveTo(v.Position)

		hum.MoveToFinished:Wait()
	end
end

while task.wait(0.5) do
	walkTo(destination)
end

Example:

You gave us a video, but what part is ‘bugging out’?
You know what’s supposed to be happening but we know nothing about how it’s supposed to be.
Are you talking about the legs dropping through the floor, it walking into the wall, or the transition from walking to crawling and back?

Well, it’s the feature where it’s transitioning from crawling to walking since the legs dropping through the floor is an animation. As well as it wouldn’t be it walking into the wall because I stated everything was going well with the pathfinding.

I’m reviving this thread because I still haven’t figured it out yet.

try to make the animation loop

It’s already looped, still experiencing issues.

Fixed it after a couple of days, all I had to do was change the other animations as it was jumping or climbing or falling sometimes.

What a relief!

1 Like