Please see the work docx and code and video attached
I.pdf (76.7 KB)
if the link does not work here is the direct video on google drive as it is too big for roblox.
Code:
local PathFinding = {}
local PFInfo = {
A = 1,
B = 10,
C = false
}
local CS = game:GetService("CollectionService")
local PFS = game:GetService("PathfindingService")
local function CheckDist(Car, Location)-- Find clostest
local closestPart
local closestMag = math.huge
for _, Work in ipairs(CS:GetTagged("Work")) do
if Work:IsA"Model" and Work.Parent == workspace then
local doorPos = Work.Door.Position
local mag = (doorPos - Car:GetPrimaryPartCFrame().Position).magnitude
if mag < closestMag then
closestMag = mag
closestPart = Work.Door
end
end
end
return Car, closestPart, closestMag
end
local function FindNode(Car)
local NodeMag
local ClosestNode
local ClosestMag = math.huge
for _, Node in ipairs(CS:GetTagged("Node")) do
if Node:IsA"Part" and CS:HasTag(Node.Parent, "Roads") then
local Nodes = Node
local Mag = (Nodes.Position - Car:GetPrimaryPartCFrame().Position).magnitude
local Car, A, Main = CheckDist(Car, "Work")
if Mag < ClosestMag and Mag > Main then
ClosestNode = Mag
ClosestNode = Node
end
end
end
return ClosestNode
end
function PathFinding.MoveTo(Car, Location)
local Car, ClosestPart, Magnitude = CheckDist(Car, Location)
local Node = FindNode(Car)
local Path = PFS:CreatePath(PFInfo)
Path:ComputeAsync(Car:GetPrimaryPartCFrame().Position, Node.Position)
local Waypoints = Path:GetWaypoints()
for _, Point in ipairs(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 = Point.Position
-- Part.Anchored = true
-- Part.Parent = game.Workspace
-- Part.CanCollide = false
Car.CarHum:MoveTo(Point.Position)
end
return Magnitude
end
return PathFinding
local PFS = game:GetService("PathfindingService")
local CS = game:GetService("CollectionService")
local Nodes = {}
local AI = require(game.ServerStorage.Modules.PathAI)
local Car = script.Parent
local NPCInfo = {
AgentRadius = 1,
AgentHeight = .5,
AgentCanJump = false
}
local Run = true
while Run == true do
wait()
local Magnitude = AI.MoveTo(Car, "Work")
print(Magnitude)
if Magnitude < 5 then
Run = false
Car:Destroy()
end
end
Please Help me. I’m starting to want to give up.