Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a GUI if player is in group and has correct rank?

I have a code where if a player is in a certain group and has a rank level or higher it will make a GUI but it won't work,

Players:IsInGroup(2723362)
if (Players:GetRoleInGroup(2723362) == "265") then
	
	local imageButton = Instance.new("ImageButton")
imageButton.Parent = screenGui
imageButton.Position = UDim2.new(0, 300, 0, 7)
imageButton.Size = UDim2.new(0, 100, 0, 100)
imageButton.Image = "rbxassetid://133293265"

It only shows if the player is in one rank not the other and it isn't a working code, How do I make it so if a player is in the group AND a rank or higher it will create the imageButton?

2 answers

✓ Accepted answer

There are four things wrong with your code. Let's go over them in order, from the simplest to the less obvious to fix.


First of all, there is a missing end keyword to close the if statement.


Secondly, you are trying to call methods IsInGroup and GetRoleInGroup on the Players service, the service responsible for holding Player objects. You want to call them on a Player object, a specific player.


Third, you are calling IsInGroup, but you never "capture" its return value in a variable and use it in an if statement. In other words, you ask whether the player is in a specific group, but you don't "listen" or "care" about the answer; so the only condition being checked is whether or not the role of the player is equal to "265".

This one is a logic issue. Adding the missing if statement will fix this:

local groupId = 2723362

if player:IsInGroup(groupId) then
	if player:GetRoleInGroup(groupId) >= requiredRank then
		-- do something.
	end
end

Or, using the and operator, one could shorten it to a single if statement:

local groupId = 2723362

if player:IsInGroup(groupId) and player:GetRoleInGroup(groupId) >= requiredRank then
	-- do something.
end

Finally, you check whether the return value of a call to GetRoleInGroup(2723362) is equal to "265", which, if we look at the Roblox Wiki page for GetRoleInGroup does not make sense, as it returns the "role" or "title" of the player as a string -- unless, for some very odd reason, your group's roles are numbers.

I am thinking you meant to call GetRankInGroup(2723362), which instead would return a number that corresponds to the "hierarchical position" of the player's role within the group. But even if you did use this instead of GetRoleInGroup, the following comparison to "265" wouldn't make sense, as the Wiki tells us the return value of GetRankInGroup is a number between 0 and 255, whereas you are comparing it to the string value "265".


Conclusion

Sure, there are a lot of little mistakes to fix, but don't worry, you'll eventually get the hang of it.

Anyway, I hope this helped. If it did then please be sure to accept, and optionally upvote, my answer. It helps both of us. ;) If you need anything else, you need only ask.

2 comments

0

Why is roblox telling me player and requiredRank unknown?????? Please help

0

don't just copy and paste the script

Firstly, you're using :GetRoleInGroup() with a Rank number. What you should be using is :GetRankInGroup().

Second, using if Player:IsInGroup() then which will check if the player is actually a member of the group then check their rank using if Player:GetRankInGroup() == "255" then.

if Player:IsInGroup() then
	if Player:GetRoleInGroup() == "255" then
		-- Create the image button
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.