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

Why doesn't my part follow the path?

Asked by 8 years ago

I have been trying to write a script on giving a part some AI. Then I wrote this code and the part didn't follow the path.

--Script Made By: Troloolooolooll

--Declaring Variables
local startPos = script.Parent.Position
local endPos = game.Workspace.End.Position
local box = script.Parent
local path = game:GetService("PathfindingService"):ComputeRawPathAsync(startPos, endPos, 200)
points = path:GetPointCoordinates()

for i = 1, #points do
    box.Velocity = points[i]
end
0
Your script changes box's Velocity to a coordinate point on line 11. You might want to change that. Validark 1580 — 8y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

First of all, you set the Velocity property for some reason. You should be setting either the CFrame or Position properties. Secondly, you need to add a wait in your numerical for loop on line 10.

local startPos = script.Parent.Position
local endPos = game.Workspace.End.Position
local box = script.Parent
local path = game:GetService("PathfindingService"):ComputeRawPathAsync(startPos, endPos, 200)
points = path:GetPointCoordinates()

for i = 1, #points do
    box.CFrame = CFrame.new(points[i])
    wait(.1)
end
0
Thanks! Troloolooolooll 9 — 8y
Ad

Answer this question