Unable to add chat tags

i am attempting to add simple chat tags and the code works fine in studio but when I attempt to play it in the actual game I get the error “attempt to index nil with SetExtraData”.

chatService.SpeakerAdded:Connect(function(playerName)
    local roleInGroup = player:GetRoleInGroup(4946462) 
    local player = game.Players[playerName]

    if roleInGroup ~= "Guest" then
        local overheadUI = ReplicatedStorage.Assets.Gui.OverheadUI:Clone()
        overheadUI.Main.Label.Text = roleInGroup
        overheadUI.Main.Label.TextColor3 = playerTitleColors[roleInGroup]
        if player.Character == nil then
            local connection 
            connection = player.CharacterAdded:Connect(function(char)
                overheadUI.Parent = char.Head
                connection:Disconnect()
            end)
        else
            overheadUI.Parent = player.Character.Head
        end

        local speaker = chatService:GetSpeaker(player.Name)
        speaker:SetExtraData("Tags", {playerChatTags[roleInGroup]})
    end
end)

On the first line you are trying to do local roleInGroup = player:GetRoleInGroup(4946462) Even though you haven’t defined player yet.

As for this part speaker:SetExtraData("Tags", {playerChatTags[roleInGroup]})

I haven’t test myself however I believe you need to lay it out like this.

speaker:SetExtraData(“Tags”, {TagText = playerChatTags[roleInGroup],})

If this doesn’t fix the issue then run print statements to ensure the speaker is the player.

1 Like

yup, I completely forgot about the first line. I will try this out.