basically, I want to fix this humanoid.jump looping error, however, I must’ve tried a million times to figure out what to do. Nothing I have done has worked, at least not essentially, in the end, I truly have no idea what to do.
I tried using a separate index number… 2 or 3, still didn’t work. Here is the code:
local bot = script.Parent
local humanoid = bot:FindFirstChildWhichIsA(“Humanoid”)
local rootpart = bot:FindFirstChild(“HumanoidRootPart”)
local pfs = game:GetService(“PathfindingService”)
local targetDistance = 1000
local wanderX = 5
local wanderZ = 5
local currentlyWandering = false
local wanderingEnabled = true
local ambience = rootpart:FindFirstChild(“Ambience”)
if ambience then
ambience.Playing = true
end
local function FindNearestTarget()
local nearestTarget = nil
local nearestDistance = math.huge
for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") and plr.Character:FindFirstChildWhichIsA("Humanoid") and plr.Character:FindFirstChildWhichIsA("Humanoid"):GetState() ~= Enum.HumanoidStateType.Dead then
local target = plr.Character
local distance = (rootpart.Position - target.HumanoidRootPart.Position).Magnitude
if distance <= targetDistance and distance < nearestDistance then
nearestTarget = target.HumanoidRootPart
nearestDistance = distance
end
end
end
return nearestTarget
end
game:GetService(“RunService”).Heartbeat:Connect(function()
local currentTarget = FindNearestTarget()
local currentWaypoint = nil
local JumpWaypoint = nil
for _, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
if not rootpart.Anchored then
v:SetNetworkOwner(nil)
end
end
end
if currentTarget then
local path = pfs:CreatePath({
AgentHeight = 5,
AgentRadius = 2,
AgentCanJump = true
})
local success, errorMessage = pcall(function()
path:ComputeAsync(rootpart.Position, currentTarget.Position)
end)
if success and path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
currentWaypoint = waypoints[2]
JumpWaypoint = waypoints[3]
path.Blocked:Connect(function()
path:ComputeAsync(rootpart.Position, currentTarget.Position)
end)
else
warn("Path not computed:", errorMessage)
return
end
else
currentlyWandering = true
end
if currentWaypoint then
if currentWaypoint.Action == Enum.PathWaypointAction.Walk or currentWaypoint.Action == Enum.PathWaypointAction.Jump then
currentlyWandering = false
end
if JumpWaypoint ~= nil and JumpWaypoint.Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
humanoid:MoveTo(currentWaypoint.Position)
elseif wanderingEnabled then
currentlyWandering = true
end
end)
humanoid.Running:Connect(function(speed)
rootpart.FootStep.Playing = speed > 0
end)