How to make A TextButton show if you are a certain rank inside a group

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m looking to try to make something simple. A TextButton will show if you are a certain rank inside a group, and if you click it, it will disable the GUI.

  2. What is the issue? Include screenshots / videos if possible!
    I have a GUI that when clicked, disables the GUI. I just need help making a script that only makes the button appear if you are a certain rank.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried to look for a few videos on YT, no luck. :frowning:

thank you so much! :smiley:

https://developer.roblox.com/en-us/api-reference/function/Player/GetRankInGroup

This is very easy to achieve. If you have any questions, feel free to ask.

local Player = game.Players.LocalPlayer
local GroupId = 000000 -- The ID of the group.
local GroupRank = 255 -- Ranges from 1 to 255.
local Button = nil -- Your gui Button

if Player:GetRankInGroup(GroupId) == GroupRank then
	Button.Visible = true -- The user is ranked "GroupRank"
else
	Button.Visible = false -- The user is not ranked "GroupRank"
end
2 Likes

I would recommend wrapping it inside a pcall, like this -

local Success,Result =  pcall(function()
    return Player:GetRankInGroup(GroupId)
end)

if Success then
   if Result >= GroupRank then
      Button.Visible = true
   else
      Button.Visible = false
   end
else
   warn(Result)
end
2 Likes

Yes, that’s a good idea to make the script more safe. I’ll make the changes.

Here is the updated script including pcall as suggested by @Valkyrop.

Script:

local Player = game.Players.LocalPlayer
local GroupId = 000000 -- The ID of the group.
local GroupRank = 255 -- Ranges from 1 to 255.
local Button = nil -- Your gui Button

local Success, Result = pcall(function()
	return Player:GetRankInGroup(GroupId) -- Gets the rank of the player in the group.
end)

if Success then -- Check if the script has successfully retrieved the rank of the player.
	if Result >= GroupRank then
		Button.Visible = true -- The user is the rank "GroupRank".
	else
		Button.Visible = false -- The user is not the ranked "GroupRank".
	end
else
	warn(Result) -- Outputs a warning when there is an error getting the rank of the player.
end