How to make a TextButton only work if you are in certain group

i’ve been trying to make a script that makes it so a TextButton will only work if the player is in a certain group, could anybody help me?

Use the script to check the rank of the player if it is a certain rank, higher, lower, or exactly that rank.

If you mean actual code, you can refer to other websites that show you how to check ranks, or just use a free model and paste the code into the script and modify as needed.

Try this.

local plr = game.Players.LocalPlayer
local button = script.Parent
local minrank = 0
local groupid = 000000

button.MouseButton1Click:Connect(function()
if plr:GetRankInGroup(groupid) >= minrank then
--code here
end
end)

Hope it works!

1 Like

i dont want the button to work on certain ranks, if you are any rank in a group you can enter, thats what i meant with the message

Well, people who aren’t in a group have a rank of 0 (I think, or maybe 1). This means that you can just see if they are in the group with any rank above 0

higher, lower, or exactly that rank. I basically said use these operators: <, >, <=, >=

I said “certain rank” in case. I state that you could use “higher, lower, or exactly that rank”. So yes, that relates to the fact that it can also apply to every rank. That would be every rank above Guest (the roblox role for non-group member).

Just put minimum rank to 0 for it to work for anybody in the group.

it didnt show any errors on the command bar but the button still works, i used a group id that im not in and yet the button worked even without me being in the group

sorry i meant to say output not command bar

1 needs to be the minimum, not 0. 0 allows for the Guests in the group (the people who aren’t in the group) to use it, while 1 only allows the lowest rank of the group, and only includes people in the group.

Set the minimum to 1, or else non group members would be allowed to use the button.

Try replacing minimum rank with 1.

i tried still nothing, i am very confused cuz the output isnt showing any errors

Could you show me the code you put? I want to look at it real quick to see if I spot an error that isn’t showing up in the output.

sure, quick context, the button is for a group team only, so yeah thats whats the script is for

local frame = script.Parent.Parent
local event = game.ReplicatedStorage["Switch Teams"]
local plr = game.Players.LocalPlayer
local button = script.Parent
local minrank = 1
local groupid = 14125759

button.MouseButton1Click:Connect(function()
	if plr:GetRankInGroup(groupid) >= minrank then
		for index, button in ipairs(frame:GetChildren()) do
			button.MouseButton1Down:Connect(function()
				event:FireServer(button.Name)
			end)
		end
	end
end)

Please allow me a few minutes to look at the script.

Try this.

button.MouseButton1Click:Connect(function()
	if plr:GetRankInGroup(groupid) >= minrank then
		for index, button in ipairs(frame:GetChildren()) do
				event:FireServer(button.Name)
			end)
		end
	end
end)

They could use Player:IsInGroup, which returns a boolean, instead of Player:GetRankInGroup.

1 Like

nothing, even though im not in the group i used the id of the game still allows me to click the button

1 Like

now the output has this message

> The Parent property of 
> a
>  is locked, current parent: NULL, new parent ReplicatedFirst