-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroup check.lua
71 lines (59 loc) · 1.55 KB
/
Group check.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
local function BlankFunc() end
local function GetService(...): Instance
local Service = game:GetService(...)
return cloneref and cloneref(Service) or Service
end
local function MergeTables(Table1, ...): SharedTable
for _, Table in next, {...} do
for Key, Value in next, Table do
Table1[Key] = Value
end
end
return Table1
end
local Players: Players = GetService("Players")
local GroupService = GetService("GroupService")
local GroupWatch = {
Watching = {}
}
function GroupWatch:Watch(Params)
-- Default options
local Group = {
Id = 0,
MinRank = 0, -- The lowest rank to trigger a callback
MaxRank = nil,
Callback = BlankFunc,
Enabled = true
}
local Info = GroupService:GetGroupInfoAsync(Params.Id)
MergeTables(Group, Params, Info)
table.insert(self.Watching, Group)
return Group
end
function GroupWatch:Check(Player: Player)
for _, Group in next, self.Watching do
-- Wether the script should ignore the group
if not Group.Enabled then continue end
local GroupID = Group.Id
local Success, Rank = pcall(Player.GetRankInGroup, Player, GroupID)
if not Success or not Rank then
continue
end
local MinRank = Group.MinRank
local MaxRank = Group.MaxRank
if (Rank >= MinRank) and (MaxRank and Rank <= MaxRank or true) then
Group.Callback(Player, Rank, Group)
end
end
return self
end
function GroupWatch:ScanPlayers()
for _, Player: Player in next, Players:GetPlayers() do
GroupWatch:Check(Player)
end
return self
end
Players.PlayerAdded:Connect(function(Player: Player)
GroupWatch:Check(Player)
end)
return GroupWatch