Need help scripting friends with dev chat tags

I’m trying to write some code that enables anyone on the developer’s friends list to have a chat tag. (That way my friends are encouraged to play my game!)

After some experimenting, I haven’t been able to do this! Is there a problem with my code?

Script in ServerScriptService:

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

local friendtags = {
	{TagText = "friends w dev",TagColor = Color3.fromRGB(121, 123, 255)},
}

chatService.SpeakerAdded:Connect(function(playerName)
	local speaker = chatService:GetSpeaker(playerName)
	local player = game.Players[playerName]
	
	 if player:IsFriendsWith(game.CreatorId) then
			speaker:SetExtraData("Tags", {friendtags[player.UserId]})
		end
end)

You are trying to get the friendtags table by userId, but the table is only an array with 1 table object. Turn it into a dictionary by having a userId as a key.

I’m really bad with dictionaries and arrays. How could I do this?

No need to use dictionaries here; you can just access the first element of the array by doing friendtags[1].

So this would work?

speaker:SetExtraData("Tags", {friendtags[1]})

Yes, that should work fine, since now you are referencing the thing within the table.

1 Like