This repository was archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsPlayers.module.lua
More file actions
107 lines (82 loc) · 2.53 KB
/
sPlayers.module.lua
File metadata and controls
107 lines (82 loc) · 2.53 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--// Initialization
local PlayerService = game:GetService("Players")
local Module = {}
--// Functions
function Module.IsTeamMate(PlayerOne, PlayerTwo)
--/ Returns if PlayerOne and PlayerTwo are on the same team
return PlayerOne.Team == PlayerTwo.Team
end
function Module.GetPlayersWithinRadius(Position, Radius, PlayerList)
PlayerList = PlayerList or PlayerService:GetPlayers()
local PlayersFound = {}
for PlayerIndex, Player in next, PlayerList do
if Player.Character then
if Player.Character:FindFirstChild("HumanoidRootPart") then
if (Player.Character.HumanoidRootPart.Position - Position).magnitude <= Radius then
table.insert(PlayersFound, Player)
end
else
warn(Player.Name .. " does not have a HumanoidRootPart and cannot be checked for Position")
debug.traceback()
end
else
warn(Player.Name .. " does not have a character and cannot be checked for Position")
debug.traceback()
end
end
return PlayersFound
end
function Module.GetObjectOwner(Descendant, AcceptNPCs)
--/ Returns the Player and Character that the Descendant is part of
assert(typeof(Descendant) == "Instance", "Descendant must be an Instance")
local Character = Descendant
local Player
repeat
if Character.Parent then
Character = Character.Parent
Player = PlayerService:GetPlayerFromCharacter(Character)
else
return nil
end
until Player or AcceptNPCs and Character:FindFirstChild("Humanoid")
return Character, Player
end
function Module.GetObjectOwnerPlayer(Descendant)
local Character, Player = Module.GetObjectOwner(Descendant, false)
return Player
end
function Module.GetFriendsInServer(RequestingPlayer)
local RequestingPlayerId = RequestingPlayer.UserId
local FriendsInServer = {}
for PlayerIndex, Player in next, PlayerService:GetPlayers() do
if Player:IsFriendsWith(RequestingPlayerId) then
if Player.UserId ~= RequestingPlayerId then
table.insert(FriendsInServer, Player)
end
end
end
return FriendsInServer
end
function Module.BindToPlayers(Function)
PlayerService.PlayerAdded:Connect(Function)
for _, Player in next, PlayerService:GetPlayers() do
spawn(function()
Function(Player)
end)
end
end
function Module.BindToPlayerCharacter(Player, Function)
Player.CharacterAdded:Connect(Function)
if Player.Character ~= nil then
Function(Player.Character)
end
end
function Module.BindToCharacters(Function)
Module.BindToPlayers(function(Player)
Player.CharacterAdded:Connect(Function)
if Player.Character then
Function(Player.Character)
end
end)
end
return Module