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

TextLabel Display Player In Group?

A box the shows staff, set text player(s) of a rank in group. Player1, player 2.

local groupId = 641111
local group = game:GetService("GroupService"):GetGroupInfoAsync(groupId)

script.Parent.Text = idk what here

1 answer

✓ Accepted answer

You mean like box that will show their rank?

local Player = your player
local GroupId = 641111

local PlayerRankInGroup = Player:GetRankInGroup(GroupId)

print(PlayerRankInGroup)

--> Their rank (number)

This will show the number rank of player in the group if this is what you want. To set it to text then just do

script.Parent.Text = PlayerRankInGroup

So here is what you would need for the label, you would need a server script as local scripts will only make it be seen-able for the player. To get name of the player you need to get the actual player, there are few ways of how you can do it, the best in this case would be PlayerAdded event of service Players. Whenever a player is added, the event will fire and you can connect it to a function.

local Players = game:FindService("Players") -- get the players service

Players.PlayerAdded:Connect(function(Player) -- the first and only argument that the event returns is Player that has joined the game
	local PlayerName = Player.Name -- Here you've got the name!
end)

Now let's get his rank

local Players = game:FindService("Players")
local GroupId = 641111

Players.PlayerAdded:Connect(function(Player)
	local PlayerName = Player.Name
	local PlayerRank = Player:GetRankInGroup(GroupId)
end)

Now here is the rank! But it's number, i guess you want the string. For that here is possible solution, you can check if rank is a specific rank by doing

if PlayerRank == 5 then

But if you have multiple ranks in group then it would not be that fast as if you could check if rank is higher than minimal staff rank.

local MinimumStaffRank = 61 -- For example, this is the minimal rank in group you must be to get the staff role, max rank is 255 in groups if i'm sure
local StaffRankName = "Staff" -- Example what text will the label have if you are a staff

local GroupId = 641111

local Players = game:FindService("Players")

Players.PlayerAdded:Connect(function(Player)
	local PlayerName = Player.Name
	local PlayerRank = Player:GetRankInGroup(GroupId)

	if PlayerRank >= MinimumStaffRank then -- Here it checks if your rank is higher than rank 61 in this case
		PlayerRank = StaffRankName -- If it is true then it will convert your rank into a string which in variable is StaffRankName 
	end
	
	print(PlayerName)
	print(PlayerRank)
end)

--> Output for Bob with rank 70
2:00:00 - Bob (Example name)
2:00:00 - Staff (Since he is higher rank than 61)

Now since this is just an example, this won't work the best but you can make it work better. It has problems such as if you are not the MinimumStaffRank then your rank will still be a number but as i said, just an example.

2 comments

0

Kinda. So the text would = the players name. ex admin name in the group would be the text. Basically so I could have part of my gui show whos staff.

0

I have edited my post a bit, is this what you wanted?

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