Non-Caching Extended Group Functions

Non-Caching Extended Group Functions

Hello DevForum, some weeks ago I made a module that allows me to retrieve the group rank / role of a user without having it cache, and some days ago I extended the module to have many other functions like checking if the user is in the groups clan or if the user set the group as the primary group.

The module entirely works with UserIds, which means that you can even use it on players who are currently not playing your game.

It is both available on GitHub and as a Module. You can grab the module here or you go to the GitHub Page and run the installer in your command line. With the newest version, you can also require it with require(2477978137) to always stay on the latest version.

The installer retrieves the latest version of the module and adds an example into ServerScriptService.

Example

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local GetModule = function(dir, name) return dir:FindFirstChild(name) and require(dir:FindFirstChild(name) or {} end
local GroupService, GroupServiceOffline = GetModule(ReplicatedStorage, "GroupService")

local GROUP_ID = 0

--------------------------------------
-- Online Example
function playerAdded(player)
  local groupRank, isPrimary = GroupService:GetRankInGroupAsync(player.UserId, GROUP_ID), 
    GroupService:IsPrimaryGroupAsync(Player.UserId, GROUP_ID)
  print("Group Rank:", groupRank)
  print("Is Primary:", isPrimary)
end

--------------------------------------
-- Offline Example
function getUserInfo(userId)
  local groupRank, isPrimary = GroupService:GetRankInGroupAsync(player.UserId, GROUP_ID), 
    GroupService:IsPrimaryGroupAsync(userId, GROUP_ID)
  print("Group Rank:", groupRank)
  print("Is Primary:", isPrimary)
end

The API Documentation can be found here.

27 Likes

This is actually pretty useful. How exactly does it work? Is it getting Roblox 's API or some other method?

I’m using Roblox it’s GroupService to receive all groups the user is in, then I go through each group and check if the group is the same as the id that has been given in the function, if it is, then I return the role / rank back. It is the almost same process for every other function.

Being a Group Business Man, I think I can find use of this. Thanks!

That’s super smart!
I knew of GroupService’s existence but never thought about using it for this.
Now that I know that these functions do not cache I think I’m going to change some stuf in my scripts!

Cool module, thanks :slight_smile:

2 Likes

Yeah I explored the API reference once and stumbled upon groupservice and tried some stuff out. When I realised that it doesn’t cache I figured that I could use it for some neat things like non-caching GetGroupRank / Role.

1 Like

This is a post that is on the devforums.

Yeah, I updated the code on GitHub but never had time to update the module or the example code above. I will try and do it today.

1 Like

Updated the example and the module available on Roblox. I also removed the ability to check if someone is in a Clan since Clans got sunsetted.

1 Like

For some reason I can’t read the API Doc. It throws back a 404.

Thank you for making this :slight_smile:. I currently do not have a use for this but I surely will do in the future!

I will look into that as soon as I can. Most likely is because my domain expired, may be some other issue also.

Updated the post properly to the newest version and updated all links. The module on Roblox should also be on the newest version now.