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
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