Hello, I’ve been looking everywhere to see how I would be able to get the rank from an offline player, using UserID. I’ve seen mentions of using GetGroupsAsync which provides a table of all the user’s groups. Great, now I have to search through to find my group and the rank associated with it. This is where I am stuck at, I am not exactly sure how I would go about doing this.
local Group = 0 -- My group ID, ofc
local function checkRank(userId)
local success, rank = pcall(function()
local UserGroups = game:GetService("GroupService"):GetGroupsAsync(userId)
local UserGroupData = table.find(UserGroups, Group)
if UserGroupData ~= nil then
local rank = table.find(UserGroupData, "rank")
-- To find the rank value here..?
end
end)
if success then
return rank
else
warn("Failed to check rank for UserID:", userId, " issue: "..rank)
end
end
Hopefully, someone can provide some helpful information on finding the group rank through the GetGroupsAsync function
pretty sure GetGroupsAsync returns a list of tables, so you couldnt just use table.find (which only works on lists, not tables).
you may have to do smth like
function FindTableInListByKey(List, KeyName, KeyValue) --list is UserGroups, keyname is 'Id' (make sure its a string), keyvalue is your groups id
for _,table in iparis(List) do
if table[KeyName] == KeyValue then
return table
end
end
return nil
end
to find UserGroupData, then do UserGroupData['Rank'] for the numerical rank (ie 255) or UserGroupData['Role'] for the rank name (ie Owner)
i havent tested anything ive said yet and have based all my info off the roblox wiki page, so be warned.
I found the solution to this problem, after combining things together and such. Here is my final result:
local function checkRank(userId, group)
local success, rank = pcall(function()
local UserGroups = game:GetService("GroupService"):GetGroupsAsync(userId)
for _,v in ipairs(UserGroups) do
if v.Id == group then
return v.Rank
end
end
end)
if success then
return rank
else
warn("Failed to check rank for UserID:", userId, " issue: "..rank)
end
end