Group button rank only

How would I go about making a button function if a player is a certain rank in a group?

3 Likes

Well, you can make use of

Putting two and two together, an example would be:

script.Parent.MouseButton1Click:Connect(function() -- fired when button is pressed!

  if Player:GetRankInGroup(groupid) == 255 then -- checks if they are a certain rank in given group!
     print("player is correct rank!")
  else print("player is not correct rank!")
  end

end)


3 Likes

I am trying to figure out if I can make the button function after checking the players rank, if that makes sense lol. Thanks for some tips though!

Oh! In that case you’d just put the function inside of the if statement!

If it were a localscript, you could do:

if game.Players.LocalPlayer:GetRankInGroup(groupid) == 255 then
      script.Parent.MouseButton1Click:Connect(function()
      end)
else
end

Though I’m not certain this is what you’re looking for, can you elaborate on what type of button?

1 Like
local Button = script.Parent
local Player = game.Players.LocalPlayer
local Rank = Player:GetRankInGroup(123456789)

if Rank >= 150 then
     Button.Visible = true
end

Would something like that work?

Ok, thank you! I need this for a fire alarm system so it doesn’t get spammed and seeing as I have never scripted a group rank button I just needed some tips on how to do it, this should help a lot. :slight_smile:

If it’s a ClickDetector then you need to use script.Parent.MouseClick rather than MouseButton1Click.

Oh! So adding on from what @CanadianDefenders said you could do a localscript, and from there you would be able to do:

local ClickDetector = x

if game.Players.LocalPlayer:GetRankInGroup(groupid) == 255 then
    ClickDetector.MouseClick:Connect(function()

     -- what you could do is fire a remote event to set off the fire alarm system!

     end)
end

But that exposes the fire alarm toggle to exploiters. So the addition of a server-side check would be useful just to make sure the people clicking it are in the group.

-- Server

local Event = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player)
	local Rank = Player:GetRankInGroup(ID)
	
	if Rank >= 150 then
		-- do fire code
	else
		print("Player "..Player.Name.." has been detected exploiting Remote Events.")
		Player:Kick("Exploiting Remote Events!")
	end
	
end)

@TheSpeedyLeopard Make sure to implement a sanity check like this on the server side, otherwise as @xZylter mentioned you are opening the fire system to exploiters.

1 Like

Can you give more information on this “button”

Example is it a PlayerGui Button or a ClickDetection Part Button?

I wouldn’t advise something like that; using visibility would mean an exploiter could just make the button visible; removing any security presented by such a feature.

1 Like

Very true. However if a sanity check is implemented on the server side (as I’ve written above), the exploiter will be stopped regardless.

Though I do agree with what you’re saying; a more ‘radical’ solution should be opted for, such as Destroying the instance.

2 Likes

What you should use is: Bindable Functions.

Just make it send a click and its will check on the serverside and Return a value on this value you can make the button go denied or allowed.