module.DefaultNameColor = Color3.new(1, 1, 1)
Above is the part that I need help with. How do I change it to be a team color tag?
I don't think that im right but it may be:
module.DefaultNameColor = game:GetService("Players").LocalPlayer.TeamColor.Color
Namaste it is i, dual
Before I get into anything, I would like to say that it's very important, you specify your code snippet is from the ChatSettings
module in ClientChatModules
, a folder in the Chat
service. Otherwise the people helping with your solution spend up to 1 hour searching through unnecessary things for the source.
On a sidenote to this whole thing, I would just like to say your chat colour automatically matches your team colour.
Now, first of all I would like to thank you for this question. I unexpectedly took this question to respond to far quicker than I ended up doing, and I had not expected to do as much research as I did. As a thanks, I upvoted your question. I would also like to say thanks to SinisterMemories for helping me with this. Now, to get into the actual solution.
First of all, you have to realise that players first must be in a team to have a team colour.
So first, add make the Team
service available to your game.
This is done by going to Model > Service > Select 'Team' > Insert
.
(https://developer.roblox.com/articles/Team-Basics-on-Roblox)
Now, you can create a team in 3 different ways:
local teams_service = game:GetService("Teams") new_team = Instance.new("Team") new_team.Parent = teams_service
Via command line:
local teams_service = game:GetService("Teams") new_team = Instance.new("Team") new_team.Parent = teams_service
Via "Advanced Objects" menu
Open the AO menu using CTRL+i
or CMD+i
, and type in Team
, then Enter
.
After following any of these, you will have a team object in your Teams
folder. Keep in mind that the Team object created with the script gets garbage collected (removed) every time you stop the play session, the rest stay there permanently.
Firstly, I want to address my first misconception. I first tried to address this problem by modifying the DefaultNameColor
from
https://developer.roblox.com/articles/Lua-Chat-System/API/ChatSettings
but I shortly found out that DefaultNameColor
was one of the methods from that page which did not function as expected when edited - the color simply would not change.
Anyhow, carrying on, you want to create a Folder called ChatModules
(yes, the name is necessary). And inside that folder create a BoolValue
called InsertDefaultModules
(again, name is neccesary). You want to set this BoolValue
to true, it will 'import' every module that normally gets added to ChatModules
at run-time, but now you have your own folder to add in whatever modules you want (which is what we will dive into next).
This folder now acts as a proxy to the original ChatModules
folder.
Next, you want to insert a ModuleScript
into this folder. It doesn't matter what you name it, as we're not conforming to a lackful API documentation, but instead its YOUR code. What you want your module script to look like is:
local Teams = game:GetService("Teams") return function(chatService) chatService.SpeakerAdded:Connect(function(speakerName) local speaker = chatService:GetSpeaker(speakerName) speaker:SetExtraData("NameColor", Teams.Team.TeamColor.Color) -- speaker:SetExtraData("NameColor", Color3.fromRGB(0, 0, 255)) -- Example using Color3 end) end
The first thing to note here is that the Chat
service is implicitly passed to every module in the ChatModules
folder. So we can return a function with the service as its parameter, and it will be passed as an argument automatically.
Secondly, SpeakerAdded
does not return the object itself, but rather the player's name as a string. We will need to get our own object using this string.
Thirdly, we need to use :SetExtraData
on the newly-created speaker object to set a value to NameColor
. All the possible values are found here:
https://developer.roblox.com/articles/Lua-Chat-System/API/ChatMessage
However, do not be mislead by the wiki! You do not need a dictionary here, but rather string, value
pair. In our case, we need the "NameColor"
string, and a Color3
value serving as the value. Reference:
https://devforum.roblox.com/t/chat-coding-working-with-tags-and-name-colours/132648/2
Fourthly, we need to decide what to set as the value. We have already gotten the Teams
service at the top, so we can index our team, and thus get all of its properties. My team was simply called "Team"
, so make sure to change it to whatever YOUR team is called. It should be noted that just doing Teams.Team.TeamColor
does not work here, as TeamColor
is a BrickColor
, not a Color3
, the accepted data type here.
(https://developer.roblox.com/api-reference/property/Team/TeamColor)
A BrickColor
data type can be converted into a Color3
data type by using its .Color
method.
So we can use Teams.Team.TeamColor.Color
here
And that is it! Now every speaker has the same name colour as their team! I spent 2 hours of my time researching this, you spent probably 10 minutes reading this, that guy's answer probably worked fine, all for nothing! As this is done automatically by Roblox itself.
But hey, what's done is done.
Closed as Non-Descriptive by EpicMetatableMoment and alphawolvess
This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.
Why was this question closed?