Problem in pathfinding waypoints

So I wanted to do somewhat a spell that creates a path leading to the target called in the spell but it only creates the path parts in the position at the target’s humanoidrootpart it doesn’t create a path. what’s the error?

-- !strict

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character
local PathfindingService = game:GetService("PathfindingService")
local Path = PathfindingService:CreatePath()
local Hrp = Char:WaitForChild("HumanoidRootPart")

local function OnPathCreating(PlayerHrp, TargetHrp)
	Path:ComputeAsync(PlayerHrp.Position, TargetHrp.Position)
	local WayPoints = Path:GetWaypoints()
	for i, trailpath in pairs(WayPoints) do
		local Parts = Instance.new("Part")
		Parts.Anchored = true
		Parts.Size = Vector3.new(0.5, 0.5, 0)
		Parts.CanCollide = false
		Parts.Material = Enum.Material.Neon
		Parts.BrickColor = BrickColor.new("Lime green")
		Parts.Parent = workspace
		wait(.1)
	end
end

Player.Chatted:Connect(function(Msg)
	local Message = Msg:lower()
	for i, v in pairs(Players:GetChildren()) do
		if Message == "find "..v.Name:lower() then
			local TargetHrp = v.Character.HumanoidRootPart
			OnPathCreating(Hrp, TargetHrp)
		end
	end
end)

Any help is appreciated

You still weren’t setting the Part’s position to the Waypoint.

Parts.Position = trailpath.Position
1 Like

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