hes supposed to be fast
but i can outrun him ON FOOT
-- Variables --
local DamageSystem = require(game:GetService("ServerScriptService"):WaitForChild("DamageSystem"))
local Pathfinding = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
script.Parent:WaitForChild("HumanoidRootPart"):SetNetworkOwner(nil)
local path = Pathfinding:CreatePath({
AgentHeight = 2;
AgentRadius = 1.5;
AgentCanJump = false;
Costs = {
Water = 100;
DangerZone = math.huge
}
})
local Character = script.Parent
local humanoid = Character:WaitForChild("Humanoid")
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local attackdebounce = false
local attackanim = humanoid:LoadAnimation(script.Attack)
local function findTarget()
local maxDistance = 500
local nearestTarget
local distance
for index, player in pairs(Players:GetPlayers()) do
if player.Character then
local target = player.Character
distance = (Character.HumanoidRootPart.Position - target.HumanoidRootPart.Position) .Magnitude
if distance < maxDistance then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget, distance
end
local function followPath(destination)
local sucess, errorMessage =pcall(function()
path:ComputeAsync(Character.HumanoidRootPart.Position, destination)
end)
if sucess and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
print("blocked")
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)
humanoid.MoveToFinished:Wait()
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
humanoid.MoveToFinished:Wait()
else
warn("Path not computed! :(", errorMessage)
end
end
while wait() do
local target, distance = findTarget()
if target and target:WaitForChild("Humanoid").Health > 0 then
if distance > 1 then
followPath(target.HumanoidRootPart.Position)
else
attackdebounce = true
attackanim:Play()
attackanim:AdjustSpeed(4)
Character:WaitForChild("HumanoidRootPart"):WaitForChild("Swing"):Play()
local distance = (Character.HumanoidRootPart.Position - target.HumanoidRootPart.Position) .Magnitude
if distance < 1.5 then
Character:WaitForChild("HumanoidRootPart"):WaitForChild("Hit"):Play()
DamageSystem.DamageTargetWithAttacker(1,target,Character)
attackdebounce = false
else
attackdebounce = false
end
end
end
end