-- NPC Pathfinding Script (Server-Side) -- Place in NPC local PathfindingService = game:GetService("PathfindingService") local npc = script.Parent local destination = workspace.Target local function moveToTarget(targetPosition) -- Create a path to the target local path = PathfindingService:CreatePath({ AgentRadius = 2, AgentHeight = 1, AgentCanJump = true, AgentJumpHeight = 5, AgentMaxSlope = 45 }) -- Compute the path to the target path:ComputeAsync(npc.HumanoidRootPart.Position, targetPosition.Position) -- Check if the path was successfully computed if path.Status == Enum.PathStatus.Success then local waypoints = path:GetWaypoints() -- Move the NPC along the waypoints for _, waypoint in ipairs(waypoints) do npc.Humanoid:MoveTo(waypoint.Position) npc.Humanoid.MoveToFinished:Wait() end else print("No path found!") end end moveToTarget(destination)
Project File (FREE) Here:
www.patreon.com/posts/roblox-studio-ai-111712034?Link&
-- NPC Pathfinding Script (Server-Side) -- Place in NPC
local PathfindingService = game:GetService("PathfindingService")
local npc = script.Parent
local destination = workspace.Target
local function moveToTarget(targetPosition)
-- Create a path to the target
local path = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 1,
AgentCanJump = true,
AgentJumpHeight = 5,
AgentMaxSlope = 45
})
-- Compute the path to the target
path:ComputeAsync(npc.HumanoidRootPart.Position, targetPosition.Position)
-- Check if the path was successfully computed
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
-- Move the NPC along the waypoints
for _, waypoint in ipairs(waypoints) do
npc.Humanoid:MoveTo(waypoint.Position)
npc.Humanoid.MoveToFinished:Wait()
end
else
print("No path found!")
end
end
moveToTarget(destination)
thanks man ...found your video ....really what i was looking for all this time ;D