You can write your topic however you want, but you need to answer these questions:
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.
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.
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.
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
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
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