Getting a groups Role name from the Rank

Hello, I made a simple whitelist system for my game.

local Players,GroupService = game:GetService("Players"),game:GetService("GroupService")

local MinRole = 4
local GroupInfo = GroupService:GetGroupInfoAsync(game.CreatorId)

Players.PlayerAdded:Connect(function(P)
	if P:GetRankInGroup(game.CreatorId) < MinRole then
		P:Kick([[This game is currently open exclusively to people in the "]] ..  .. [[" role in the game's group, please wait until release!]])
	end
end)

How do I have it so that the code gets the Role name from the MinRole variable?
I theorized that you would make a simple iteration through the GroupInfo.Roles table but I don’t know how to do that, so I need some help!

Thanks

You would want to index the Roles field of GroupInfo. Roles is an array of roles, and you would want to find the role with the matching rank.

I know how to index the Roles table of GroupInfo, but the problem is how I’m going to iterate through that table (containing every role’s information in my group) to return the Name string

You could use a for loop to iterate through the table.

for _, role in GroupInfo.Roles do
-- Check
end

This was one of my initial ideas, but I was skeptical to try it. I’ll give it a shot.

Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.