Chattags break chat and nobody can see chat

So, I made some chat tags for myself and VIPs and my script seems to not let anybody see chat and I can’t seem to figure what causes it, any ideas?

local textChatService = game:GetService("TextChatService")
local marketplaceService = game:GetService("MarketplaceService")
textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	if message.TextSource then
		local prefixes = ""
		
		
		
		local player = game:GetService("Players"):GetPlayerByUserId(message.TextSource.UserId)
		
		if marketplaceService:UserOwnsGamePassAsync(player.UserId, 205290393) then
			prefixes ..= "<font color='#fcd303'>[VIP] </font>"
		end	
		
		if player.Name == "cozfl" then
			prefixes ..= "<font color='#fcd303'>[boing] </font>"
		end
		if player.Name == "930mossburg" then
			prefixes ..= "<font color='#fcd303'>[cozfl's Alt] </font>"
		end

		properties.PrefixText = prefixes .. message.PrefixText -- After, add the name (?) or whatever this is
	end
	return properties
end

I assume its a small fix, any help would be greatly appreciated

I’m not sure if you have already fixed this issue but,

I had the same issue for a while and I was so lost on how it kept breaking then later finally realized that you cannot use server-sided functions like UserOwnsGamePassAsync from MarketPlaceService in that code since it’s a LocalScript so what you can do is either make a RemoteEvent/RemoteFunction to call such from a server script or attach attributes to a player.

I went with the second option, you could do something like this in the ServerScript:

local Admins = {
    1234567890,
    -- user IDs here
}

local MarketplaceService = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)	
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAMEPASS_ID_HERE) then
		player:SetAttribute('IsVIP', true)
	end
	
	if table.find(Admins, player.UserId) then
		player:SetAttribute('IsAdmin', true)
	end
	
        -- can expand, add more stuff here like for group ranks, etc
end)

Then you’d do something like this in the local script where the code for chat tags are at:

local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	
	local textSource = message.TextSource
	local chattingPlayer = if textSource
		then Players:GetPlayerByUserId(textSource.UserId)
		else nil

	if chattingPlayer then
		if chattingPlayer:GetAttribute("IsAdmin") == true then
			properties.PrefixText = "<font color='#F5CD30'>[ADMIN]</font> " .. message.PrefixText
		elseif chattingPlayer:GetAttribute("IsVIP") == true then
			properties.PrefixText = "<font color='#ADD8E6'>[💎 VIP]</font> " .. message.PrefixText
		end
	end
	
	return properties
end

Hope this helps!

1 Like