-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet.lua
85 lines (72 loc) · 2.24 KB
/
Get.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Player.CharacterAdded:Connect(function(C)
Character = C
end)
local function GetAllPlayers(CheckFunc)
local Plrs = {}
for _, Plr in pairs(Players:GetPlayers()) do
if CheckFunc(Plr) and Plr.Character and Plr.Character:FindFirstChild("HumanoidRootPart") then
Plrs[#Plrs + 1] = Plr
end
end
return Plrs
end
local function GetClosestPlayer(From, CheckFunc)
CheckFunc = CheckFunc or function()
return true
end
local Closest = {
Distance = math.huge,
User = nil,
Char = nil,
Root = nil
}
for _, Plr in pairs(Players:GetPlayers()) do
if CheckFunc(Plr) and Plr ~= Player and Plr.Character and Plr.Character:FindFirstChild("HumanoidRootPart") then
local Dist = ((From or Character.HumanoidRootPart.Position) - Plr.Character.HumanoidRootPart.Position).Magnitude
if (Dist < Closest.Distance) then
Closest.Distance = Dist
Closest.User = Plr
Closest.Char = Plr.Character
Closest.Root = Plr.Character.HumanoidRootPart.Position
end
end
end
return Closest
end
local function GetClosestObject(Objects)
local Closest = {
Distance = math.huge,
Object = nil
}
for _, Object in pairs(Objects) do
local Dist = (Character.HumanoidRootPart.Position - Object.Position).Magnitude
if (Dist < Closest.Distance) then
Closest.Distance = Dist
Closest.Object = Object
end
end
return Closest
end
local function GetClosestObjects(Objects)
local Closest = {
Distance = math.huge,
Object = nil
}
for _, Object in pairs(Objects) do
local Dist = (Character.HumanoidRootPart.Position - Object.Position).Magnitude
if (Dist < Closest.Distance) then
Closest.Distance = Dist
Closest.Object = Object
end
end
return Closest
end
return {
AllPlayers = GetAllPlayers,
ClosestPlayer = GetClosestPlayer,
ClosestObject = GetClosestObject,
ClosestObjects = GetClosestObjects
}