Hello! Recently I’ve been having an issue with a group-getting script (to minimize Http requests). The script works perfectly in my small test game, but when I put it inside of the actual game which has much more going on, it totally breaks.
The error occurring is shown in the picture below:
It is also worth mentioning that in getTable(), the print does indeed print the table with the player data. However, later it prints “is nil”, and when getTable() is supposed to run again, it remains nil. I’m so confused honestly.
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GetRankInGroup = ReplicatedStorage.Bindables:WaitForChild("GetRankInGroup")
local GetRoleInGroup = ReplicatedStorage.Bindables:WaitForChild("GetRoleInGroup")
local IsInGroup = ReplicatedStorage.Bindables:WaitForChild("IsInGroup")
local plrGroupData = {}
local function getTable(plr)
repeat wait() pcall(function() plrGroupData[plr.Name] = GroupService:GetGroupsAsync(plr.UserId) end) until plrGroupData[plr.Name] ~= nil
print(plrGroupData[plr.Name])
end
local function plrAdded(plr)
getTable(plr)
local character1 = plr.Character or plr.CharacterAdded:Wait()
plr.CharacterAdded:Connect(function()
getTable(plr)
end)
end
local function plrRemoving(plr)
if plrGroupData[plr.Name] then
plrGroupData[plr.Name] = nil
end
end
Players.PlayerAdded:Connect(plrAdded)
Players.PlayerRemoving:Connect(plrRemoving)
GetRankInGroup.OnInvoke = function(groupId, plr)
if plrGroupData[plr.Name] == nil then
plrGroupData[plr.Name] = getTable(plr)
print("is nil")
end
print(plrGroupData[plr.Name])
for _,group in pairs(plrGroupData[plr.Name]) do
if group.Id == groupId then
return group.Rank
end
end
return 0
end
IsInGroup.OnInvoke = function(groupId, plr)
if plrGroupData[plr.Name] == nil then
plrGroupData[plr.Name] = getTable(plr)
print("is nil")
end
for _,group in pairs(plrGroupData[plr.Name]) do
if group.Id == groupId then
return true
end
end
return false
end
GetRoleInGroup.OnInvoke = function(groupId, plr)
if plrGroupData[plr.Name] == nil then
plrGroupData[plr.Name] = getTable(plr)
print("is nil")
end
for _,group in pairs(plrGroupData[plr.Name]) do
if group.Id == groupId then
return group.Rank
end
end
return "Guest"
end