How to Add Custom Player Icons to Chat

Woah, this is going to be great - about to go and add it to my game now :pray:
Edit:
image
This looks pretty cool.

4 Likes

There’s a problem, isn’t there someway to set it by grabbing the decal? Because subtracting the number takes longer since Roblox is trying to patch it cause users are stealing other user’s clothing.

Decal IDs are different from image IDs. You can get the image ID by finding the image you want in the toolbox, and then right-clicking on it and choosing the “copy image URL” option. Subtracting numbers from the decal ID until you find the image ID isn’t really feasible anymore.

5 Likes

I found two other ways of doing this easily with an extension, and another way by doing it VIA studio:

  1. BTRoblox: Find it VIA Chrome store, you can see it here > Find the decal, click from your images on the create page to be directed to the decal page > You’ll see an image button on the top right area (as seen here) > Click the image button, it will take you directly to the page where your image is (as seen here)

  2. Studio: Workspace > + > Decal > Properties > Paste in your decal ID > Wait a second, you’ll notice the ID changes > Your ID will then be converted to the image asset ID, just copy it from the decal properties and you’ll find it. Gyazo Preview

I personally use BTRoblox for multiple things, it has many benefits including being able to view model sources from the site including scripts.
image
image

The second one is practically pointless, it’s much easier doing it the way mentioned by ChipioIndustries.

4 Likes

Love this! However I am having a problem. The image does not appear in chat and I am getting this error in output;

19:39:27.941 - Mesh Manager: http request failed, contentid: 'rbxassetid://4342232872', exception: HTTP 403 (Forbidden)

I don’t know why, does somebody know how I can fix this?

sorry

just read the discussion, I was using the decal id, not image.

How did u set it in the ExtraDataInitializer?

I got it working. I don’t really understand the question, but it was because I was using the decal id, not the image id

Alright, I mean’t that too my bad.

Any idea what i have done here?

https://gyazo.com/b77a0c57d57004d586fb9de5efc080cc

should only show 1.

Afraid I can’t help ya much without being able to see your code. Try adding print statements in various spots to figure out what might be going wrong.

1 Like

I copied the code exactly as it said.

I worked out why it is putting the image twice but any idea why it is in the middle of my name?

I believe it is where the icons are added to the player.

How would i fix this (i used your code exactly as you typed it)

This is quite an interesting idea. You could show in-game clans and much more like real moderators instead of 9-year olds pretending to be mods.

Great! Now I can add this free model to my camping game :roblox:

I can’t help you fix your script if you won’t provide it. If your code isn’t functioning the same way as mine, there must be a mistake somewhere. Try just using the free model and seeing if that works.

1 Like

So how would I add to the icons a roblox admin icon for example?

MY SCRIPT FOR THE EXTRADATAMODULE:

--	// Written by: Xsitsu
--	// Description: Module that sets some basic ExtraData such as name color, and chat color.

-- // Chat Icon Amendment by ChipioIndustries.
-- // Based on latest chat version as of 10/10/2019
-- // Edits on lines 32, 80, 110, 216

local SpecialChatColors = {
	Groups = {
		{
			--- ROBLOX Interns group
			GroupId = 2868472,
			Rank = 100,
			ChatColor = Color3.new(175/255, 221/255, 1),
		},
		{
			--- ROBLOX Admins group
			GroupId = 1200769,
			ChatColor = Color3.new(1, 215/255, 0),
		},
	},
	Players = {
		{
			--- Left as an example
			--  UserId = 2231221,
			--  ChatColor = Color3.new(205/255, 0, 0)
		}
	}
}

local SpecialChatIcons={
	Groups={
		{
			GroupId=7748598,
			Rank=254,
			Icons={"rbxasset://textures/ui/PlayerList/AdminIcon.png"},
		}
	},
	Players={
		{
			UserId= 2964877,94643687,42111501,1146407844,
			Icons= {"rbxasset://textures/ui/PlayerList/AdminIcon.png"},
		}
	}
}

local function MakeIsInGroup(groupId, requiredRank)
	assert(type(requiredRank) == "nil" or type(requiredRank) == "number", "requiredRank must be a number or nil")

	return function(player)
		if player and player.UserId then
			local userId = player.UserId

			local inGroup = false
			local success, err = pcall(function() -- Many things can error is the IsInGroup check
				if requiredRank then
					inGroup = player:GetRankInGroup(groupId) > requiredRank
				else
					inGroup = player:IsInGroup(groupId)
				end
			end)
			if not success and err then
				print("Error checking in group: " ..err)
			end

			return inGroup
		end

		return false
	end
end

local function ConstructIsInGroups()
	if SpecialChatColors.Groups then
		for _, group in pairs(SpecialChatColors.Groups) do
			group.IsInGroup = MakeIsInGroup(group.GroupId, group.Rank)
		end
	end
	if SpecialChatIcons.Groups then
		for _,group in pairs(SpecialChatIcons.Groups) do
			group.IsInGroup=MakeIsInGroup(group.GroupId,group.Rank)
		end
	end
end
ConstructIsInGroups()

local Players = game:GetService("Players")

local function GetSpecialChatColor(speakerName)
	if SpecialChatColors.Players then
		local playerFromSpeaker = Players:FindFirstChild(speakerName)
		if playerFromSpeaker then
			for _, player in pairs(SpecialChatColors.Players) do
				if playerFromSpeaker.UserId == player.UserId then
					return player.ChatColor
				end
			end
		end
	end
	if SpecialChatColors.Groups then
		for _, group in pairs(SpecialChatColors.Groups) do
			if group.IsInGroup(Players:FindFirstChild(speakerName)) then
				return group.ChatColor
			end
		end
	end
end

local function ProcessImageID(ID)
	if tonumber(ID) then
		return "rbxassetid://"..tostring(ID)
	else
		return ID
	end
end

local function GetSpecialChatIcons(speakerName)
	local chatIcons={}
	if SpecialChatIcons.Players then
		local playerFromSpeaker=Players:FindFirstChild(speakerName)
		if playerFromSpeaker then
			for _,player in pairs(SpecialChatIcons.Players) do
				if playerFromSpeaker.UserId==player.UserId then
					for __,icon in pairs(player.Icons) do
						table.insert(chatIcons,ProcessImageID(icon))
					end
				end
			end
		end
	end
	if SpecialChatColors.Groups then
		for _,group in pairs(SpecialChatIcons.Groups) do
			if group.IsInGroup(Players:FindFirstChild(speakerName)) then
				for __,icon in pairs(group.Icons) do
					table.insert(chatIcons,ProcessImageID(icon))
				end
			end
		end
	end
	return chatIcons
end

local function Run(ChatService)
	local NAME_COLORS =
	{
		Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color,
		Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color,
		Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color,
		BrickColor.new("Bright violet").Color,
		BrickColor.new("Bright orange").Color,
		BrickColor.new("Bright yellow").Color,
		BrickColor.new("Light reddish violet").Color,
		BrickColor.new("Brick yellow").Color,
	}

	local function GetNameValue(pName)
		local value = 0
		for index = 1, #pName do
			local cValue = string.byte(string.sub(pName, index, index))
			local reverseIndex = #pName - index + 1
			if #pName%2 == 1 then
				reverseIndex = reverseIndex - 1
			end
			if reverseIndex%4 >= 2 then
				cValue = -cValue
			end
			value = value + cValue
		end
		return value
	end

	local color_offset = 0
	local function ComputeNameColor(pName)
		return NAME_COLORS[((GetNameValue(pName) + color_offset) % #NAME_COLORS) + 1]
	end

	local function GetNameColor(speaker)
		local player = speaker:GetPlayer()
		if player then
			if player.Team ~= nil then
				return player.TeamColor.Color
			end
		end
		return ComputeNameColor(speaker.Name)
	end

	local function onNewSpeaker(speakerName)
		local speaker = ChatService:GetSpeaker(speakerName)
		if not speaker:GetExtraData("NameColor") then
			speaker:SetExtraData("NameColor", GetNameColor(speaker))
		end
		if not speaker:GetExtraData("ChatColor") then
			local specialChatColor = GetSpecialChatColor(speakerName)
			if specialChatColor then
				speaker:SetExtraData("ChatColor", specialChatColor)
			end
		end
		if not speaker:GetExtraData("Tags") then
			--// Example of how you would set tags
			--[[
			local tags = {
				{
					TagText = "VIP",
					TagColor = Color3.new(1, 215/255, 0)
				},
				{
					TagText = "Alpha Tester",
					TagColor = Color3.new(205/255, 0, 0)
				}
			}
			speaker:SetExtraData("Tags", tags)
			]]
			speaker:SetExtraData("Tags", {})
		end
		if not speaker:GetExtraData("Icons") then
			local specialIcons=GetSpecialChatIcons(speakerName)
			if specialIcons then
				speaker:SetExtraData("Icons",specialIcons)
			end
		end
	end

	ChatService.SpeakerAdded:connect(onNewSpeaker)

	for _, speakerName in pairs(ChatService:GetSpeakerList()) do
		onNewSpeaker(speakerName)
	end

	local PlayerChangedConnections = {}
	Players.PlayerAdded:connect(function(player)
		local changedConn = player.Changed:connect(function(property)
			local speaker = ChatService:GetSpeaker(player.Name)
			if speaker then
				if property == "TeamColor" or property == "Neutral" or property == "Team" then
					speaker:SetExtraData("NameColor", GetNameColor(speaker))
				end
			end
		end)
		PlayerChangedConnections[player] = changedConn
	end)

	Players.PlayerRemoving:connect(function(player)
		local changedConn = PlayerChangedConnections[player]
		if changedConn then
			changedConn:Disconnect()
		end
		PlayerChangedConnections[player] = nil
	end)
end

return Run```

_______________________________________


The lines of code i'm trying to add it to is this one:

```Players={
		{
			UserId= 2964877,94643687,42111501,1146407844,
			Icons= {"rbxasset://textures/ui/PlayerList/AdminIcon.png"},
		}```

(also sorry for the red and stuff i've tried fixing it)
1 Like

If you’re asking how to add an icon for Roblox admins, you would add another entry to the Groups section of SpecialChatIcons using the admins group:

local SpecialChatIcons = {
	Groups = {
		{
			GroupId = 1200769;
			Icons = {}; --icon here
		}
	}
}
4 Likes

Alrighty, thanks! I’ll try that later.

How would I give players the Admin icon by UserId?

EXAMPLE:

UserId = 1,
Icon = {0},

Yeah, that’s how you’d do it. Just add it as an entry to the Players section of SpecialChatIcons.

1 Like