Non humanoid walking backwards (pathfind)

I am trying to make a Lethal ape fangame in roblox but the monster (is non humanoid) its walking backwards
robloxapp-20250226-1500437.wmv (1.4 MB)

local d = script.Parent.AnimationController.Animator:LoadAnimation(script.Animation)
d:Play()
d:AdjustSpeed(0.5)
local PathfindingService = game:GetService("PathfindingService")
local TweenService = game:GetService("TweenService")
local path = PathfindingService:CreatePath()
local thiff = true
local speed = 100

function findPlayer()
	local foundplayer = nil
	local function raycastinplayerposition(postion1, position2)
		local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		raycastParams.FilterDescendantsInstances = {script.Parent, foundplayer}
		local raycastResult = workspace:Raycast(postion1, (position2 - postion1), raycastParams)
		if raycastResult then
			return raycastResult.Instance
		else
			return nil
		end
	end
	for i, v in pairs(game.Players:GetPlayers()) do
		if v and v.Character then
			foundplayer = v.Character
			if not raycastinplayerposition(script.Parent.RootPart.Position, v.Character.PrimaryPart.Position) then
				return foundplayer
			end
		end
	end
end

local function moveToPosition(position)
	local targetCFrame = CFrame.lookAt(position, script.Parent.RootPart.Position)
	local tween = TweenService:Create(script.Parent.RootPart, TweenInfo.new((script.Parent.RootPart.Position - position).Magnitude/speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {CFrame = CFrame.new(position + Vector3.new(0,4.4,0),script.Parent.RootPart.Position)})
	tween:Play()
	local part = Instance.new("Part", workspace)
	part.Position = position
	part.Anchored = true
	part.CFrame = targetCFrame
	local found =  findPlayer()
	while thiff do
		wait()
		while (script.Parent.RootPart.Position - position).Magnitude > 5 and thiff do
			wait()
		end
		if found then
			if not findPlayer() then
				break
			end
		end
		if (script.Parent.RootPart.Position - position).Magnitude <= 5 then
			print("finished position", position)
			break
		end
		break
	end
	part:Destroy()
end

spawn(function()
	while wait() do
		if findPlayer() then
			d:AdjustSpeed(1)
			speed = 50
			path:ComputeAsync(script.Parent.RootPart.Position, findPlayer().PrimaryPart.Position)
		else
			speed = 25
			d:AdjustSpeed(0.5)
			path:ComputeAsync(script.Parent.RootPart.Position, script.Parent.RootPart.Position + Vector3.new(math.random(-30, 30), 0, math.random(-30, 30)))
		end
		local foundpositionofplayer = if findPlayer() then findPlayer().PrimaryPart.Position else nil
		if findPlayer() and foundpositionofplayer and (findPlayer().PrimaryPart.Position - foundpositionofplayer).Magnitude > 5 then
			warn("YEa")
			thiff = false
		end
	end
end)

while true do
	local waypoints = path:GetWaypoints()
	local foundpositionofplayer = if findPlayer() then findPlayer().PrimaryPart.Position else nil

	for i, v in pairs(waypoints) do
		if thiff then
			moveToPosition(v.Position)
		end
	end
	thiff = true
	task.wait()
end


1 Like

Flips it’s Rootpart around.

That should fix the issue

1 Like

i already tried that, same problem

1 Like

change it to

TweenInfo.new(( -script.Parent.RootPart.Position + position)
maybe it will work

1 Like

robloxapp-20250226-1536463.wmv (981.5 KB)

1 Like

It doesnt have a humanoid thats why it falls, you should use humanoid or Controller manager.

1 Like