Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local aiLib = {}
- local players = game:GetService("Players")
- local params = RaycastParams.new()
- params.FilterDescendantsInstances = { workspace.Zombies }
- params.FilterType = Enum.RaycastFilterType.Exclude
- function aiLib:findNearestPlayersHrp(aiNpc, distOfInt)
- local closestHrp = nil
- local aiNpcHrp = aiNpc:FindFirstChild("HumanoidRootPart")
- for i, v in pairs(players:GetChildren()) do
- local char = v.Character
- if char then
- local hrp = char:FindFirstChild("HumanoidRootPart")
- if hrp and aiNpcHrp then
- local diff = (hrp.Position - aiNpcHrp.Position)
- local dist = diff.Magnitude
- if dist < distOfInt then
- local result = workspace:Raycast(aiNpcHrp.Position,
- diff, params)
- if result and result.Instance.Parent.Name == char.Name then
- print("closest player = ", v.Name)
- distOfInt = dist
- closestHrp = hrp
- end
- end
- end
- end
- end
- return closestHrp
- end
- return aiLib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement