How to make a button that only members of a group can see?

What do you want to achieve?
I want a button (GUI) to be only visible for members of this group (group ID: 16438390) who haves the ranks 2, 3, 4, 5, and 255.

What is the issue?
I tried a script and it didn’t worked. I placed it into a normal script under a TextButton.

The script should make the GUI to players who don’t have the rank 254, and I have the rank 255. But it doesn’t work. Also I know it only do that for the 254 rank and not for 2, 3, 4, 5, and 255 but I wanted to try. Also I don’t know how to make it for a few ranks, except using a few times the same script. And I see there are things with MouseClick, and I don’t want it to hide only when someone click it. I didn’t made this script, it comes from this topic.

function onMouseClick(player)
	local playerUI = player:FindFirstChild("PlayerGui")		

	if Player:GetRankInGroup(16438390) == 254 then	
		playerUI.ButtonGui.Frame.Visible = true
	else
		playerUI.ButtonGui.Frame.Visible = false			
	end
end
end)

clickdetector.MouseClick:Connect(onMouseClick)

What solutions have you tried so far?
I don’t know at all what I can do.

Thank in advance for your help, have a great day and happy developping!!

may you show the full script , clickdetector doesn’t appear to be defined

Is there a ScreenGui called ButtonGui in StarterGui, and a Frame called frame inside of it?

1 Like
-- Add this condition:
local ranks = {2,3,4,5}
local rank = Player:GetRankInGroup(16438390)
if table.find(ranks, rank) or rank >= 254 then
    -- code
end
1 Like

How do I add it? Can you show me it on the script?

local ranks = {2,3,4,5}

clickdetector.MouseClick:Connect(function(player)
	local rank = Player:GetRankInGroup(16438390)
	local permission = table.find(ranks, rank) or rank >= 254
	if permission then
		player.PlayerGui.ButtonGui.Frame.Visible = true
	else
		player.PlayerGui.ButtonGui:Destroy()
	end
end)

If the player doesn’t have permission to use the button, it is destroyed. This is so exploiters can’t use it if they make it visible again. If you’re using remote events, it should have the same logic to check for permission.

1 Like

I will try that!

But if they click, then the other script will works no? So the button will works once before it’s destroyed.

I think for extra extra safety reasons, you should make the permission system on the server, so that it can really check if you’re allowed to use it or not. Use RemoteFunctions!

1 Like

I don’t know at all how I can do this…

Can you show me?

local player = game.Players.LocalPlayer
local button = script.Parent

if player:IsInGroup(1) then -- change 1 to your group id
   button.Visible = true
else
   button.Visible = false
end
1 Like

I want to make that it’s shown to members with a certain rank, not to every member.