Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ServerStorage = game:GetService("ServerStorage")
- local SimplePath = require(ServerStorage:WaitForChild("SimplePath")) -- in server storage
- local Goal = nil -- goal / target
- local Bot = script.Parent -- the bot
- local Path = SimplePath.new(Bot) -- create a path
- function findnearestPlayer(Origin:Vector3,MaxDistance:number)
- local Players = game:GetService("Players")
- local NearestPlayer,NearestDistance
- for i,player in pairs(Players:GetPlayers()) do
- local character = player.Character
- local distance = player:DistanceFromCharacter(Origin)
- if not character or distance > MaxDistance or (NearestDistance and distance >= NearestDistance) then
- continue
- end
- NearestDistance = distance
- NearestPlayer = player
- end
- return NearestPlayer
- end
- while true do
- Goal = findnearestPlayer(Bot.PrimaryPart.Position,5000)
- if Goal then
- Path:Run(Goal.Character.PrimaryPart.Position)
- if (Goal.Character.PrimaryPart.Position - Bot.PrimaryPart.Position).Magnitude < 4 then
- local Humanoid = Goal.Character:FindFirstChildOfClass("Humanoid")
- if Humanoid then
- Humanoid:TakeDamage(30) -- damage
- end
- end
- end
- task.wait()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement