I cant figure out the error on my script. I am getting an error saying “Unable to cast Instance to Vector3” on line 13. I have looked on the devforum for a long time, and no luck.
local pathService = game:GetService("PathfindingService")
local startPoint = script.Parent.PrimaryPart
local humanoid = script.Parent.Humanoid
local endPoint = workspace.EnemyGoal.Value
function computePath(startPoint:Vector3, endPoint)
local Path:Path
local retriesLeft = 20
local retryInterval = 1
for i = retriesLeft, 1, -1 do
Path = pathService:CreatePath()
Path:ComputeAsync(startPoint, endPoint)
if Path.Status == Enum.PathStatus.Success then
return Path
else
warn("Path failed, retrying...")
end
end
error("path failed :sad:")
end
local function walkHumanoid(humanoid:Humanoid, startPoint:Vector3, endPoint:Vector3)
local Path = computePath(startPoint, endPoint)
local waypoints = Path:GetWaypoints()
local CurrentWaypointIndex = 2
for _, point:PathWaypoint in ipairs(waypoints) do
local Part = Instance.new("Part")
Part.Anchored = true
Part.CanCollide = false
Part.Material = Enum.Material.Neon
Part.Color = Color3.fromRGB(255,255,255)
Part.Position = point.Position
Part.Parent = workspace
Part.Size = Vector3.new(1,1,1)
end
end
computePath(startPoint, endPoint)
walkHumanoid()