Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- function findNearestTorso(pos)
- local list = workspace:GetChildren()
- local torso = nil
- local dist = math.huge
- for _, model in ipairs(list) do
- if model:IsA("Model") and model ~= script.Parent then
- -- берём только персонажей игроков
- local player = Players:GetPlayerFromCharacter(model)
- if player then
- local temp = model:FindFirstChild("HumanoidRootPart")
- local human = model:FindFirstChild("Humanoid")
- if temp and human and human.Health > 0 then
- local newDist = (temp.Position - pos).Magnitude
- if newDist < dist then
- torso = temp
- dist = newDist
- end
- end
- end
- end
- end
- return torso
- end
- while true do
- task.wait(1)
- local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
- if target ~= nil then
- script.Parent.N1:MoveTo(target.Position, target)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment