local pathfinding = game:GetService("PathfindingService")
local engine = script.Parent
local ikarus = engine.Parent.Parent
local velo = engine:WaitForChild("BodyVelocity")
local accel = 10
local brake = 25
local maxSpeed = 35
local speed = 0
local function getClosestStop()
local pos = ikarus:GetPivot().Position
local nearest
local dist = math.huge
for _, v in workspace:GetChildren() do
if v:IsA("BasePart") and v.Name:lower():find("stop") then
local d = (v.Position - pos).Magnitude
if d < dist then
nearest = v
dist = d
end
end
end
return nearest
end
local function driveTo(destination, rerouteCount)
rerouteCount = rerouteCount or 0
if rerouteCount > 5 then
warn("🛑 bus lost after too many reroutes")
speed = 0
velo.Velocity = Vector3.zero
return false
end
local start = ikarus:GetPivot().Position
local path = pathfinding:CreatePath({
AgentRadius = 4,
AgentHeight = 6,
AgentCanJump = false, -- common sense
AgentCanClimb = false -- here too
})
path:ComputeAsync(start, destination.Position)
if path.Status ~= Enum.PathStatus.Success then
warn(" bus lost, path failed")
speed = 0
velo.Velocity = Vector3.zero
return false
end
```lua
#path finding failed attempt
1 messages · Page 1 of 1 (latest)
hey man ion know bout u but u gotta RUN the functions
wdym
use pastebin
yeah i think i used them
if ur gonna be rude get ur own help
i am not
bc you cant js
okay here it is
local waypoints = path:GetWaypoints()
print("🛣️ found path with", #waypoints)
if DEBUG_PATH then
drawDebugPath(waypoints)
end
for i = 1, #waypoints do
local wp = waypoints[i]
local reached = false
while not reached do
if isBlocked(destination) then
print(" lock on road, time for shortcut (reroute attempt " .. (rerouteCount+1) .. ")")
speed = 0
velo.Velocity = Vector3.zero
task.wait(0.5)
return driveTo(destination, rerouteCount + 1)
end
local pos = ikarus:GetPivot().Position
local dir = (wp.Position - pos)
local dist = dir.Magnitude
if dist < 2 then
reached = true
else
local diff = maxSpeed - speed
if math.abs(diff) > 0.1 then
speed += math.sign(diff) * ((diff > 0) and accel or brake) * 0.1
end
velo.Velocity = dir.Unit * speed
end
task.wait(0.05)
end
end
speed = 0
velo.Velocity = Vector3.zero
print(" arrived. brakes working. nobody dead.")
return true
end
local function startBus()
while true do
local stop = getClosestStop()
if stop then
local success = driveTo(stop)
if success then
break
else
warn("❌ bus failed to reach stop, retrying in 2 seconds")
task.wait(2)
end
else
warn("❌ no stops found. bus is confused.")
break
end
end
clearDebug()
end
startBus()
i even tried asked chatgbt but even it crashed
got this from a path finding template, and tweaked it
heres half of the code
** You are now Level 2! **
can you give more info
well
copy paste it into a part, with a body velocity
like trying to caculate how the bus gonna get to the first way point is complex
with body velocity and angular velocity, too complex
wait what line does it say lost
old verison, or this
this
wdym old and new
nvm
is the script you sent the new version
ye
not new version, half of the script, but either way, new version it dosent say lost
it just does nothing
the lost log is no stops found
add a wait
where
before startBus()
same result
it just draws debug path, rn its not needed
yh but its not defined
local function drawDebugPath(waypoints) clearDebug() local folder = Instance.new("Folder") folder.Name = "BusPathDebug" folder.Parent = workspace for i = 1, #waypoints do local wp = waypoints[i] local part = Instance.new("Part") part.Anchored = true part.CanCollide = false part.Shape = Enum.PartType.Ball part.Size = Vector3.new(1,1,1) part.Position = wp.Position part.Color = Color3.fromRGB(255, 200, 0) part.Transparency = 0.3 part.Name = "WP_"..i part.Parent = folder if i > 1 then local prev = waypoints[i-1] local beam = Instance.new("Part") beam.Anchored = true beam.CanCollide = false beam.Size = Vector3.new(0.3,0.3,(wp.Position-prev.Position).Magnitude) beam.CFrame = CFrame.new(prev.Position, wp.Position) * CFrame.new(0,0,-beam.Size.Z/2) beam.Color = Color3.fromRGB(255, 100, 0) beam.Transparency = 0.5 beam.Name = "Line_"..(i-1) beam.Parent = folder end end end
DEBUG_PATH is true
yh idk srry but js check if each function is running
if everything aint working correctly, it would throw an error anyways
wait a second, im going to make a test part...
yo
this test run works
@tame magnet the test run works, then why does this not work?