the issue’s is blatant but the solutions i’ve tried so far was from a “thread”? and it didn’t work
if im being honest i dont know how to fix this
preview: https://cdn.calones.xyz/15aab11fd8273480.mp4
code:
local humanoid = character:FindFirstChild("Zombie")
local humroot = character:FindFirstChild("HumanoidRootPart")
local pathfindingservice = game:GetService("PathfindingService")
local path = pathfindingservice:CreatePath({
AgentRadius = 1,
AgentHeight = 4,
AgentCanJump = true,
AgentCanClimb = true,
WaypointSpacing = 8,
Costs = {
Climb = 2,
}
})
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local follow = true
local function visualizeWaypoint(waypointPosition)
local visual = Instance.new("Part")
visual.BrickColor = BrickColor.Red()
visual.Anchored = true
visual.Size = Vector3.new(0.5, 0.5, 0.5)
visual.CanCollide = false
visual.Transparency = 0.5
visual.Position = waypointPosition
visual.Parent = workspace
end
local function followpath(destination)
local success,errormsg = pcall(function()
path:ComputeAsync(character.PrimaryPart.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)
visualizeWaypoint(waypoints[nextWaypointIndex].Position)
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
visualizeWaypoint(waypoints[nextWaypointIndex].Position)
else
warn("error lol: ", errormsg)
end
end
function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 1000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
coroutine.wrap(function()
local target = findNearestTorso(humroot.Position)
while follow == true and target do
task.wait()
followpath(target.Position)
end
end)()
i just need to figure out how to fix this so that’s my achivement