Unable to cast double to Vector3

Hey There,

I have problem with PathFindingSerive.I tried to move NPC to random waypoint but it throws an error

  17:41:22.162  Unable to cast double to Vector3  -  Server - Script:10

I cant find any solution that related to my problems
this is the scripts:

local NPC = script.Parent
local humanoid = NPC.Humanoid
local way = game.Workspace.WaypointPlayer:GetChildren()
local point = math.random(1 , #way)


local PathService = game:GetService("PathfindingService")

local path = PathService:CreatePath()
path:ComputeAsync(NPC.UpperTorso.Position, point)
local waypoints = path:GetWaypoints()

for i , v  in pairs(waypoints)do
	humanoid:MoveTo(v.Position)
	humanoid.MoveToFinished:wait(1)
	humanoid:MoveTo(v.Position)
end

any help is apperciated :slight_smile: :slight_smile:

1 Like

Do:
point = way[math.random(1,#way)].Position

:ComputeAsync() takes 2 parameters, a starting position (Vector3) and an end position (Vector3). You provided a Vector3 for the first parameter but ‘point’ is a number determined by math.random() (hence the actual error you’re getting).

I’m assuming ‘game.Workspace.WaypointPlayer’ contains some sort of instances with a position property (I’m not sure what objects they are so I can’t guarantee). In the example of if the children of WaypointPlayer are parts, then you would replace:

path:ComputeAsync(NPC.UpperTorso.Position, point)

with:

path:ComputeAsync(NPC.UpperTorso.Position, way[point].Position)

If the objects are Vector3Values, you would replace that line with this instead:

path:ComputeAsync(NPC.UpperTorso.Position, way[point].Value)

Please do let me know if you have any questions :slight_smile:

Thanks got it working :smiley:

1 Like

Wow thanks for the information :smiley: :smiley:

1 Like

No problem, I’m glad you managed to get it working! :grin:

1 Like