Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] NPC pathfinder, Error with position which is not a valid member of Vector 3 ?

Asked by
Tixabel 19
4 years ago
Edited 4 years ago

Im creating a pathfinder for an NPC named zombie, i'm trying to make the NPC move to it's destination where it has to make it to it's destination by walking over a plank and turning left toward the Green Flag.

I created a script which is placed in a serverScriptService

THIS IS MY CODE

local zombie = game.Workspace.Zombie
local humanoid = zombie.Humanoid
local GreenFlag = game.Workspace.GreenFlag
local path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(zombie.Torso.Position,GreenFlag.Position,400)


local waypoints = path:GetPointCoordinates()

for _, waypoint in pairs(waypoints) do
    local part = Instance.new("Part")
    part.Shape = "Ball"
    part.Material = "Neon"
    part.Size = Vector3.new(0.6,0.6,0.6)
    part.Position = waypoint.Position  --Position is not a valid member of Vector3
    part.Anchored = true
    part.CanCollide = false
    part.Parent = game.Workspace

    humanoid:MoveTo(waypoints.Position)
    humanoid.MovedTpFinished:Wait()
end

I was using Roblox wiki, pathfinder tutorial and it's a bit confusing for me, then i used other sources to help me, like some answers from script helpers but i am still struggling.

I don't know what i did wrong from line 14 part.Position = waypoint.Position, but it's not accepting it and therefore i can't make a trail that would lead to the flag, or the NPC to follow it. Please help.

SOLVED, HERES THE CODE

local zombie = game.Workspace.Zombie
local humanoid = zombie.Humanoid
local GreenFlag = game.Workspace.GreenFlag
local path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(zombie.Torso.Position,GreenFlag.Position,400)

print (path)

local waypoints = path:GetPointCoordinates()

print(waypoints.Position)

for _, waypoint in pairs(waypoints) do
    local part = Instance.new("Part")
    part.Shape = "Ball"
    part.Material = "Neon"
    part.Size = Vector3.new(0.6,0.6,0.6)
    part.Position = waypoint
    part.Anchored = true
    part.CanCollide = false
    part.Parent = game.Workspace

    humanoid:MoveTo(waypoint)
    humanoid.MoveToFinished:Wait()
end

1 answer

Log in to vote
0
Answered by 4 years ago

thats because "waypoint" is already a vector3, you dont need the ".Position" simply remove it

0
Thnx Tixabel 19 — 4y
Ad

Answer this question