Need help with ranking system for chat

i want to make this so i don’t need to call the players but instead get the group rank 0-255

and if i can make this more compact that would be nice lol

yes i have looked at the Player | Roblox Creator Documentation and i don’t get how to do it still lol

local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local Players = game:GetService("Players")

local Owner = {
	["leadScientist"] = {"me"};
	["coFounder"] = {"team"};
	["test"] = {"Members"};
} -- Add roales and usernames

ChatService.SpeakerAdded:Connect(function(PlrName)
	local Speaker = ChatService:GetSpeaker(PlrName)
	for _, v in pairs(Owner.leadScientist) do
		if Players[PlrName].Name == v then
			Speaker:SetExtraData('Tags', {{TagText = "[lead scientist]", TagColor = Color3.fromRGB(255,0,0)}}) --Change the numbers to what you want the color to be, you get the color code from a part when you choose what color it should be. 
		end
	end
	
	for _, v in pairs(Owner.coFounder) do
		if Players[PlrName].Name == v then
			Speaker:SetExtraData('Tags', {{TagText = "[co-founder]", TagColor = Color3.fromRGB(46, 255, 0)}}) --Change the numbers to what you want the color to be, you get the color code from a part when you choose what color it should be. 
		end
	end
	
	for _, v in pairs(Owner.test) do
		if Players[PlrName].Name == v then
			Speaker:SetExtraData('Tags', {{TagText = "test", TagColor = Color3.fromRGB(0, 102, 255)}}) --Change the numbers to what you want the color to be, you get the color code from a part when you choose what color it should be. 
		end
	end		
end)

Would you not just use :GetRankInGroup() method from the players service and then check if the rank ID is inside of the table using table.find(). If it is inside of the table you would then just change there chat tag.

that’s the thing i don’t know how to implement that

Kon’nichiwa! :bowing_woman:t2:

Here are some changes based on the code you have written.

local GroupID = 000--'<< Put Your Group ID here'
local Ranks = {{"RankName",Color3.fromRGB(255,0,0)},
		{"Owner",Color3.fromRGB(255,0,0)},
		{{"Member",Color3.fromRGB(255,0,0)},
	}--This is a table containing the info you want to retrieve. Just make sure the first string is the exact name of your rank.
ChatService.SpeakerAdded:Connect(function(PlrName)
	local Speaker = ChatService:GetSpeaker(PlrName)
	local RankName = Speaker:GetRoleInGroup(GroupID)
	for i,RankData in pairs(Ranks) do
		if RankData[1] == RankName then
			Speaker:SetExtraData('Tags', {{TagText = RankData[1], TagColor = RankData[2]}}) 
			return
		end
	end
end)

In this Verison you need the rank number, not the exact rank name. And you need to set what you want the tag name to be.

local GroupID = 000--'<< Put Your Group ID here'
local Ranks = {{0,"Tag_Name",Color3.fromRGB(255,0,0)},
		{1,"TagName1",Color3.fromRGB(255,0,0)},
		{2,"TagName2",Color3.fromRGB(255,0,0)},
	}--This is a table containing the info you want to retrieve. Make sure the number before Tag_Name matches the ranks number.
ChatService.SpeakerAdded:Connect(function(PlrName)
	local Speaker = ChatService:GetSpeaker(PlrName)
	local RankId = Speaker:GetRoleInGroup(GroupID)
	for i,RankData in pairs(Ranks) do
		if RankData[1] == RankId then
			Speaker:SetExtraData('Tags', {{TagText = RankData[2], TagColor = RankData[3]}}) 
			return
		end
	end
end)

Let me know if you need me to explain more!

local GroupID = 000--'<< Put Your Group ID here'
local Ranks = {{0--[[the rank number]],"Tag_Name"--[[tag as in the name of the rank?]],Color3.fromRGB(255,0,0)},
		{1,"TagName1",Color3.fromRGB(255,0,0)},
		{{2,"TagName2",Color3.fromRGB(255,0,0)},

ChatService.SpeakerAdded:Connect(function(PlrName)
	local Speaker = ChatService:GetSpeaker(PlrName)
	local RankName = Speaker:GetRoleInGroup(GroupID)
	for i,RankData in pairs(Ranks) do
		if RankData[1] == RankName then
			Speaker:SetExtraData('Tags'--[[do i replace this or not]], {{TagText = RankData[1], TagColor = RankData[2]}}) 
			return
		end
	end
end)

I recommend you learn lua before trying to attempt to code. It’s kinda clear you don’t understand at all and just looking to be code fed.

yeah good point but i’m just starting out give some slack : p

when i get better i’ll have less need for help i need to get there first lol that’s how all forms of learning work it’s a big point of stem learning

Where it says 0 for example, put the rank number.
Then where it says Tag_Name put what you want the tag to say.

ALSO.
You sort of mixed/combined the two different scripts I sent you, instead just use one or the other.
The top one uses the Rank Name, so you dont need to set a custom name.

The second script uses the Rank Number, so you can set a custom text for the Tag.

Don’t mix both, just use one or the other.


Here’s more info:

local GroupID = 000

Replace the 000 with your group ID. We are setting/assigning a variable. We are telling the rest of the script below that any time we type GroupID, it really means the number we put instead of 000.

local Ranks = {{0,"Tag_Name",Color3.fromRGB(255,0,0)},}

Here instead of using a number like we did with the GroupID. Instead, we are making a new variable that represent a table. Tables are like a way to make a list of different types of data.
Creating a table is as simple as making these two braces… one to open ‘{’ one to close the table’}’ so it looks like this: {}

For the ranks table I made a table… { }
Then I put another table inside of that table. I know its weird, but im basically making a list… of a list. {{ }}
So now I have a table… with one thing inside of it… another table!
Inside of the new table, I want to list all of the info for a rank I am going to use… So…
First I list the Rank number that the other info is attached to. {{0}}
Then I add a comma to list the next thing, which is what the tag will be called. {{0,‘TagName1’,}}
lastly, I add another comma to add to the list. The Color that the tag will use! {{0,‘TagName1’,Color3.fromRGB(255,0,0)}}

Now I have all the information listed for rank 0… But what about other ranks? Like rank 2?

That is EXACTLY WHY we put this table, inside of another table. Because now we can make two tables and put them both inside the main table!! like this…

{{0, 'TagName1', Color3.fromRGB(255,0,0)}, {2, 'TagName2', Color3.fromRGB(255,0,0)}}

Moving on…

for i,RankData in pairs(Ranks) do
end

We are using a for loop, and pairs(). Basically, we just check through the list we made. and use the information we need.

local Ranks = {--[[This first brace starts the MAIN table.]]
		{--[[This brace starts a table INSIDE the table.]] 0,"Tag_Name",Color3.fromRGB(255,0,0)}--[[This brace ends the table INSIDE the table.]],-_This is a comma because we have something to list after this.
		{1,"TagName1",Color3.fromRGB(255,0,0)},--This is another table, and a comma.
		{2,"TagName2",Color3.fromRGB(255,0,0)},--This is another table, and a comma.
	}--This brace ends/closes the MAIN table.

All of this is to help you understand some of the code, but honestly, I haven’t used this SetExtraData thing you are doing. I am mainly answering how to use the group ranks.

This can help if you have issues with setting text data.
In-Experience Text Chat | Roblox Creator Documentation

thanks for the help so much, i’ll put it together when i’m back at my pc ( :