How do I make a click detector only available to multiple group ranks?

So, I have a minor question, I would like to know how only specific group ranks that I choose can use my click detector. Just so you know, I would like to select multiple group ranks for it, not just one. Is there a way to do this?

You can check their group rank by adding a player function to the args. then using if player:GetRankInGroup(id) > minRank then

Of course!

You could follow this: Group button rank only but do IF this OR that, or multiple if statements - or if the group rank ID is > a certain group rank ID.

Is there a way to make a table with the group ranks?

You could store all the group ranks in a table, and then use table.find:

if table.find(tableName, Player:GetRankInGroup(groupid)) then
      script.Parent.MouseButton1Click:Connect(function()
            -- Code Here
      end)
end

A good way to do it would be store all the numbers in a table, and when someone clicks on the button, check if they’re one of those ranks in the group and allow them to use it, otherwise, do nothing

local detector = script.Parent.ClickDetector

local ranks = {
	240,
	230,
	200
	--Continue if needed
}

local groupId = --Your groupId

detector.MouseClick:Connect(function(plr)
	if not table.find(ranks,plr:GetRankInGroup(groupId)) then return end
	--Code
end)

Similar to how @TheReal_CatCrafter stated, but that would only really work if it was in a LocalScript, this will work even in a regular script

Also again, really would recommend using guard clauses rather than full if statement if you don’t care about the other result in order to help readability by removing some indentation

2 Likes

I am getting an error at the plr part.

Image:

You forgot to put plr in brackets at function()

How do you do that? I am dumb.

It shows you how I did it in my example, you can figure it out from there

Like this?

Image:

Yes, that is how it is done for what you need