AI on rigged blender model not working

So I have a blender model rigged and has a HumanoidRootPart (and it is set as primarypart) and I am trying to program it a pathfinding service.

The issue is that when I try to use Humanoid:MoveTo it doesnt work but if I make it do something else afterwards it does that other thing my code:

local BossModel = Boss.Boss
local Hum = Boss.Humanoid
local Root = Boss.HumanoidRootPart

local roar = Hum:LoadAnimation(Boss.Roar)

Hum:MoveTo(workspace.Part.Position)
Hum.MoveToFinished:Connect(function()
 print("Hi")
end)

basically it doesnt move to the part but still prints “Hi”

I have tried to find ways to solve it but it doesnt work. (I don’t want an entire script I just want to know the solution on how to fix it)


(sorry for the bad handwriting I am not used to writing using my mouse)

1 Like

Maybe you need the

PathfindingService

I made a Script with an Pathfinding-Ai for another game of mine
And you would probably just need to Change the Part.

local NPC = script.Parent
local humanoid = script.Parent.Humanoid

local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection

for _, part in pairs(script.Parent:GetChildren()) do 
	if part:IsA("Part") then 
		part:SetNetworkOwner(nil) 
	end
end
for _, part in pairs(script.Parent:GetChildren()) do 
	if part:IsA("BasePart") then 
		part:SetNetworkOwner(nil) 
	end
end

humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)

for i, player in ipairs(game.Players:GetPlayers()) do
	script.Parent.HumanoidRootPart:SetNetworkOwner(player)
end

local PathfindingService = game:GetService("PathfindingService")

local function getPath(destination)
	local pathParams = {
		["AgentHeight"] = 3.5,
		["AgentRadius"] = 0.8,
		["AgentCanJump"] = false,
		["WaypointSpacing"] = 1,
		["AgentCanClimb"] = false,
	}

	local path = PathfindingService:CreatePath(pathParams)

	local waypointss = path:GetWaypoints()
	--
	path:ComputeAsync(NPC.HumanoidRootPart.Position, destination.Position)
	for _, part in pairs(script.Parent:GetChildren()) do 
		if part:IsA("BasePart") then 
			part:SetNetworkOwner(nil) 
		end
	end

	path.Blocked:Connect(function()
		for _, part in pairs(script.Parent:GetChildren()) do 
			if part:IsA("BasePart") then 
				part:SetNetworkOwner(nil) 
			end
		end
		print("Path is blocked, Generating new Path..")
		path:ComputeAsync(NPC.HumanoidRootPart.Position, destination.Position)
	end)


	return path

end

local function walkTo(destination)
	local path = getPath(destination)
	for _, part in pairs(script.Parent:GetChildren()) do 
		if part:IsA("BasePart") then 
			part:SetNetworkOwner(nil) 
		end
	end


	for index, waypoint in pairs(path:GetWaypoints()) do
		for _, part in pairs(script.Parent:GetChildren()) do 
			if part:IsA("BasePart") then 
				part:SetNetworkOwner(nil) 
			end
		end
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end
end

local PartToWalk = --//Put your Part Here

walkTo(PartToWalk)
1 Like

thank you so much dude! It actually works :smiley:

1 Like

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