Issue with giving player chat tag when they join if a bool value inside of them is set to true

For some reason the player doesn’t get the chat tag, the datastore works for the bool value, it’s set to true when I look in the character model. Here’s the script in server script service:

game.Players.PlayerAdded:Connect(function(player)

if player.BackpackItems.EpicChatTag.Value == true then

local speaker = chatService:GetSpeaker(player.Name)

speaker:SetExtraData("Tags", {{TagText = "EPIC"}})

speaker:SetExtraData("ChatColor", Color3.fromRGB(0,255,255))

end

end)```

This is probably because “BackpackItems” and/or “EpicChatTag” does not exist yet. I would add a :WaitForChild().

game.Players.PlayerAdded:Connect(function(player)

if player:WaitForChild("BackpackItems"):WaitForChild("EpicChatTag").Value == true then

local speaker = chatService:GetSpeaker(player.Name)

speaker:SetExtraData("Tags", {{TagText = "EPIC"}})

speaker:SetExtraData("ChatColor", Color3.fromRGB(0,255,255))

end

end)
1 Like

Wouldn’t it just error if BackpackItems didn’t exist yet?

I would first suggest OP to try printing “speaker”, maybe it’s not getting the correct speaker for whatever reason.

In the same way, if that were true it would show errors in the console about “speaker” being nil.

Right, makes sense. I’m assuming the “EpicChatTag” bool is saved in a datastore, so it could also just be false when the check happens, and only after that does the data load in.

1 Like

He might have to add it into the script he has to load the data. Or, because I have experienced this in the past, he should move the chatSpeaker variable into the PlayerAdded function because it has a :WaitForChild() in it so it doesn’t delay the PlayerAdded function making it not run when the first player joins.

1 Like