How would i make a players name a different color in chat?

I have no idea how to use richtext or html, so I have no idea how to insert the player name into this string.

All I found is people sending the devforum post which doesnt really help me in this situation.

I’m using a custom chatbox to change the color of the player name in chat.

image
How would i change “player name here” to the actual player name?

local function rgb255RichText(color3)
	local R = (color3.R * 255)
	local G = (color3.G * 255)
	local B = (color3.B * 255)

	return string.format("rgb(%d, %d, %d)", R, G, B)
end

function createtext(stri,plr)
	local c = Text:Clone()
	local color = rgb255RichText(Color3.fromRGB(0, 55, 235))
	
	local name =  color
	
	c.Text = [[<font color="]] .. color .. [[">[ "PLAYER NAME HERE" ]</font>]] .. " " .. stri

	c.Parent = goal
end

is this running on a clientscript or server.

local script, its being received by the client from the server

so, a remote event? if so, then pass the player, and put the player name in “PLAYER NAME HERE”

else try doing localplayer.name

but thats the problem, I can’t put it in there without the chat text actually saying “plr.Name”

Huh, that’s a bit weird, I’ve never seen that. Could you show me the script where you got the player and put the name there.

i dont think its relevant, its literally just receiving a player from the server. The problem is that I cant reference the players name in the string

Ah, I’m dumb, it’s a string so when you did, plr.name, it put that there because it’s within the string.

I don’t do strings like this, but maybe try this?

c.Text = [[<font color="]] .. color .. "["..player.Name.."]" .. " " .. stri

I cannot really test around with it, because I can’t remake your entire thing, so I have to go off from what I think/know.

You should take a look at string interpolation. It’s cleaner (imo) than using the concatenation operator. You can add the player’s username like this, alongside the other variables you were mixing in. This could also be a replacement for string.format() in some cases.

c.Text = `<font color="{color}">{plr.Name}</font> {stri}`

Here’s the documentation as well if you’d like for string interpolation.