You are on page 1of 3

chasing nextbot script:

-- ok
script.Parent.PrimaryPart:SetNetworkOwner(nil)

local RunS = game:GetService('RunService')


local PFS = game:GetService('PathfindingService')
--local debris = game:GetService("Debris")

local bot = script.Parent -- bot stuff


local bhum = bot:WaitForChild('bot')
local bhrp = bot:FindFirstChild('HumanoidRootPart')
local cs = game:GetService("CollectionService")

task.wait(1)

local AgentParams = {
AgentRadius = 0.25,
AgentCanJump = true,
AgentHeight = 5.0,
WaypointSpacing = math.huge,
Costs = {
Door = 10
}
}

local findPath = PFS:CreatePath(AgentParams)


local actPath = PFS:CreatePath(AgentParams)

local followedChar -- the one we are already following

local char -- the one which we follow

task.spawn(function()
while script do
task.wait(1)
if bhrp.Velocity.Magnitude <= 4 then
if not bhum.Jump and char and char ~= nil then
bhum.Jump = true
end
end
end
end)

local function checkSight(c)


local ray = Ray.new(bhrp.Position,(c.HumanoidRootPart.Position -
bhrp.Position).Unit * 1000)
local hit,position = workspace:FindPartOnRayWithIgnoreList(ray,
{script.Parent})

if hit then
if hit:FindFirstChild("Humanoid") or
hit.Parent:FindFirstChild("Humanoid") or
hit.Parent.Parent:FindFirstChild("Humanoid") then
if math.abs(hit.Position.Y - bhrp.Position.Y) < 2 then
return true
else
return false
end
else
return false
end
else
return false
end
end

local function nearestChar()


while task.wait(.05) do
local nearChar, nearDist = nil, nil
local distance
local firstPos

for i,v in pairs(workspace:GetChildren()) do


pcall(function()
if game:GetService("Players"):GetPlayerFromCharacter(v) and
v:FindFirstChildOfClass("Humanoid").Health > 0 then
findPath:ComputeAsync(bhrp.Position,
v.HumanoidRootPart.Position)
if findPath.Status == Enum.PathStatus.Success then
distance = 0
for i,waypoint in
ipairs(findPath:GetWaypoints()) do
if i ~= 1 then
distance = distance +
(waypoint.Position - firstPos).Magnitude
end
if waypoint.Action ==
Enum.PathWaypointAction.Jump then
if char ~= nil then
bhum.Jump = true
end
end
firstPos = waypoint.Position
end
if nearDist == nil then
nearDist = distance
nearChar = v
else
if distance < nearDist then
nearDist = distance
nearChar = v
end
end
end
else
char = nil
end
end)
end
char = nearChar
end
end

spawn(nearestChar)

local count = 0

RunS.Heartbeat:Connect(function()
pcall(function()
if char ~= nil and char:FindFirstChild("HumanoidRootPart") then
local sight = checkSight(char)
if sight == true then
repeat task.wait()
bhum:MoveTo(char.HumanoidRootPart.Position)
until
checkSight(char) == false or char == nil
elseif sight == false then
actPath:ComputeAsync(bhrp.Position,
char.HumanoidRootPart.Position)
for i,v in ipairs(actPath:GetWaypoints()) do
if i ~= 1 then
bhum:MoveTo(v.Position)
bhum.MoveToFinished:Wait()
end
end
end
end
end)
end)
kill script:
function onTouched(Obj)
local h = Obj.Parent:FindFirstChild("Humanoid")
if h then
h.Health = 0
end
end

script.Parent.Touched:Connect(onTouched)

You might also like