for a,b in ipairs(script.WAYPOINTS_FOLDER.Value.InCooldownWaypoints:GetChildren()) do
b.Parent = script.WAYPOINTS_FOLDER.Value.WanderPoints
end
local PFS = game:GetService("PathfindingService")
local Bot = script.Parent.Parent
local RP = Bot:WaitForChild("HumanoidRootPart")
local Human = Bot:WaitForChild("Humanoid")
local Path = PFS:CreatePath({
AgentRadius = 2,
AgentHeight = 6,
AgentCanJump = false,
AgentMaxSlope = 80, -- Adjust based on your environment
AgentCanClimb = false, -- Adjust based on your environment
})
-- Function to wait for the humanoid to reach its destination
-- Function to follow the waypoints
local function followPath(waypoints)
for _, waypoint in ipairs(waypoints) do
Human:MoveTo(waypoint.Position)
end
end
-- Function to handle pathfinding and movement
local function moveToWaypoint(part)
Path:ComputeAsync(RP.Position, part.Position)
if Path.Status == Enum.PathStatus.Success then
local WPs = Path:GetWaypoints()
if #WPs > 0 then
followPath(WPs) -- Follow the waypoints
end
else
print("Pathfinding failed with status:", Path.Status.Name)
end
end
-- Main loop
while true do
local Folder = script.WAYPOINTS_FOLDER.Value.WanderPoints:GetChildren()
if #Folder >= 1 then
local Rnum = math.random(1, #Folder)
local Part = Folder[Rnum]
--task.spawn(function()
--Part.Parent = script.WAYPOINTS_FOLDER.Value.InCooldownWaypoints
--wait(10)
--Part.Parent = script.WAYPOINTS_FOLDER.Value.WanderPoints
--end)
moveToWaypoint(Part)
else
print("No waypoints available")
end
task.wait(0.1) -- Short wait before starting the next path
end
-- Variables --
local Bot = script.Parent.Parent
local RP = Bot:WaitForChild("HumanoidRootPart")
local Human = Bot:WaitForChild("Humanoid")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local path = game.PathfindingService:CreatePath({
AgentRadius = 4,
AgentHeight = 6,
AgentCanJump = false,
WaypointSpacing = 8, -- Adjust this value to change waypoint spacing
Costs = {
DangerZone = math.huge
}
})
local Character = script.Parent.Parent
local humanoid = Character.Humanoid
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local function followPath(destination)
local success, errormessage = pcall(function()
path:ComputeAsync(RP.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
followPath(destination)
end
end)
if not reachedConnection then
reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not Computed!", errormessage)
end
end
-- Main loop
while true do
local Folder = script.WAYPOINTS_FOLDER.Value.WanderPoints:GetChildren()
if #Folder >= 1 then
local Rnum = math.random(1, #Folder)
local Part = Folder[Rnum]
-- Start following the path to the selected waypoint
followPath(Part.Position)
-- ADD PART TO COOLDOWN NOT WORKING! PUTS ALL INSTANTLY INTO COOLDOWN!
else
print("No waypoints available")
end
task.wait(0.05) -- Short wait before starting the next path
end
WHERE DO I PUT THIS HERE? it instantly puts all of the waypoints into cooldown and then errors with no waypoints avaliable!
you could try using some sort of variable called pathCompleted and block the humanoid from traversing a new path when that variable is set to false or something
local function followPath(waypoints)
pathCompleted = false
for _, waypoint in ipairs(waypoints) do
Human:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
pathCompleted = true
end
if Path.Status == Enum.PathStatus.Success and pathCompleted then
local WPs = Path:GetWaypoints()
if #WPs > 0 then
followPath(WPs) -- Follow the waypoints
end
else
print("Pathfinding failed with status:", Path.Status.Name)
end
idk i can’t be bothered to do it perfectly, here’s an idea of what you’re supposed to do
“wi cant be bothered” what do you mean, if you dont have the intention to help why are you here? if you know the solution, tell it to me and you get your answer market as solution
If we just spoonfeed you, you won’t be able to learn anything from it. Its like asking someone to create a game for you, you have no idea what they’re doing but it works (maybe).