TextChatService: How can I send modified messages to every player?

I’m trying to make a player have black text if they bought a gamepass, when they text in the chat though, the changes don’t appear in the chat nor is their bubble chat.

How can I make this modified change show for every player?

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

TextChatService.OnIncomingMessage = function(TextChatMessage)
	if TextChatMessage.TextSource then
		local player = Players:GetPlayerByUserId(TextChatMessage.TextSource.UserId)
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId,123141231) then -- Put proper ID
		end
		local overrideProperties = Instance.new("TextChatMessageProperties")
		overrideProperties.Text = string.format("<font color='#1b1c1b'>%s</font>", TextChatMessage.Text)
		return overrideProperties
	end
end
1 Like

(code doesn’t work, do not use)

1 Like

I’m just taking it out the of MarketplaceService if statement for testing purposes and TextChatMessage isn’t a property of MessageProperties I don’t think.

1 Like

Let me open up studio and try this out real quick!

1 Like

Ah, I don’t know what made it work but its showing for everyone. I’ll probably look more into this service because its confusing.

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

TextChatService.OnIncomingMessage = function(TextChatMessage)
	if TextChatMessage.TextSource then
		local properties = Instance.new("TextChatMessageProperties")
		local player = Players:GetPlayerByUserId(TextChatMessage.TextSource.UserId)
		properties.Text = string.format("<font color='#1b1c1b'>%s</font>", TextChatMessage.Text)
		return properties
	end
end

if this code works for you, then checking the gamepass is simple:

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

TextChatService.OnIncomingMessage = function(TextChatMessage)
	if TextChatMessage.TextSource then
		local properties = Instance.new("TextChatMessageProperties")
		local player = Players:GetPlayerByUserId(TextChatMessage.TextSource.UserId)
		
		-- Check if the player owns the game pass
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 123141231) then -- Replace 123141231 with the actual game pass ID
			properties.Text = string.format("<font color='#000000'>%s</font>", TextChatMessage.Text) -- Black text for players who own the game pass
		else
			properties.Text = string.format("<font color='#1b1c1b'>%s</font>", TextChatMessage.Text) -- Default color for players who don't own the game pass
		end
		
		return properties
	end
end

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.