So uh… my script is this, what im tryna achieve is so the car npc can just wait for it and make a new pathfinding point when the wait is done, is somethings missing? the ‘‘if mag < 0.5’’ suppose to make a wait() that stops it for a while until its there, but however its not working. it just ignores it, any help?
while wait(0.001) do
local PathfindingService = game:GetService("PathfindingService")
-- Variables for the car and destination, etc.
local Debris = game:GetService("Debris")
primarypart = script.Parent
local carprimary = script.Parent.FrontBumper
local destination = script.Parent.MainTarget.Value
local TweenService = game:GetService("TweenService")
local modifier = script.Parent.Configuration.SpdModifier
local path = PathfindingService:CreatePath{
AgentRadius = 27
}
path:ComputeAsync(carprimary.Position, destination.Position)
local waypoints = path:GetWaypoints()
local part = Instance.new('Part')
for _, waypoint in pairs(waypoints) do
Debris:AddItem(part, 8.5)
part.Shape = "Ball"
part.Material = "Neon"
part.Name = "Pathfind_Point"
part.Size = Vector3.new(5.6, 0.6, 5.6)
part.Transparency = 0
part.Anchored = true
script.Parent.Target.Value = part
part.Parent = workspace
part.CanCollide = false
part.Position = waypoint.Position
local mag = (primarypart.PrimaryPart.Position - script.Parent.Target.Value.Position).Magnitude / 3.25
if mag < 0.5 then
print(mag, 'mag to path')
wait()
end
end
end