Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Some kind of pathfinding error? "Unable to cast Instance to Vector3"

I was trying to figure out pathfinding, and it was going pretty well until I ran into the error "Unable to cast Instance to Vector3." I tried looking up other solutions, but what they tried to achieve differed from what I'm attempting to, so the solutions weren't applicable. Here's the script:

while true do
	path = game:GetService("PathfindingService"):ComputeRawPathAsync(script.Parent.PointA, script.Parent.PointB, 200)
	points = path:GetPointCoordinates()
	
	script.Parent.Points:ClearAllChildren()
	
	for p = 1, #points do
		part = Instance.new("Part")
		part.FormFactor = Enum.FormFactor.Symmetric
		part.CanCollide = false
		part.Size = Vector3.new(1, 1, 1)
		part.Position = points[p]
		part.Anchored = true
		part.Transparency = 1
		part.Parent = script.Parent.Points
	end
	
	wait(.1)
end

The error was in the second line. I'm new to this, so if I did anything wrong, please tell me. Thank you!

1 comment

0

What is PointA and PointB

1 answer

This script is outdated, as GetPathCoordinates now return a Instance that has Action and Position. Also, ComputeRawPathAsync is deprecated, so use FindPathAsync. With these updates, your script should look like

while true do
    path = game:GetService("PathfindingService"):FindPathAsync(script.Parent.PointA, script.Parent.PointB, 200)
    points = path:GetPointCoordinates()

    script.Parent.Points:ClearAllChildren()

    for p = 1, #points do
        part = Instance.new("Part")
        part.FormFactor = Enum.FormFactor.Symmetric
        part.CanCollide = false
        part.Size = Vector3.new(1, 1, 1)
        part.Position = points[p].Position
        part.Anchored = true
        part.Transparency = 1
        part.Parent = script.Parent.Points
    end

    wait(.1)
end

I'd also use pairs for the for loop.

Hope this helps!

2 comments

0

I got the same error on the same line! D: Thanks for the effort though...

0

You might be misspelling it.

This discussion is preserved as it was. New answers, comments, and votes are closed.