I want to make a custom chat which i have succeed doing so far. However I want to make it so players who have purchased certain gamepasses have certain tags next to their names when they talk. For example if someone bought VIP when they say "hello world" in chat is would appear "[VIP] Player: hello world".
I have so far managed to make a chat tag next to everyones name by changing this line:
local sanitizedMessage = sender .. ": " .. game.Chat:FilterStringForPlayerAsync(message, player)
To this
local sanitizedMessage = "[VIP]" .. sender .. ": " .. game.Chat:FilterStringForPlayerAsync(message, player)
I'm just not sure on how to make a function that changes this if a player has a certain gamepass. The code so far:
The Chat: http://prntscr.com/8uqzyv
local messageData = {}
local MAX_MESSAGES = 10
----GamePass----
local passId = 0000000
----GamePass----
local function storeMessage(sender, message)
for _, player in pairs(game.Players:GetPlayers()) do
local sanitizedMessage = sender .. ": " .. game.Chat:FilterStringForPlayerAsync(message, player)
local playerMessages = messageData[tostring(player.userId)]
-- table.insert(messageData[tostring(player.userId)], sanitizedMessage)
-- if #messageData[tostring(player.userId)] > MAX_MESSAGES then
-- table.remove(messageData[tostring(player.userId)], 1)
-- end
-- game.ReplicatedStorage.SendMessages:FireClient(player, messageData[tostring(player.userId)])
table.insert(playerMessages, sanitizedMessage)
if #playerMessages > MAX_MESSAGES then
table.remove(playerMessages, 1)
end
game.ReplicatedStorage.SendMessages:FireClient(player, playerMessages)
end
end
game.Players.PlayerAdded:connect(function(player)
local playerMessages = {}
messageData[tostring(player.userId)] = playerMessages
player.Chatted:connect(function(message)
storeMessage(player.Name, message)
end)
player.CharacterAdded:connect(function(character)
game.ReplicatedStorage.SendMessages:FireClient(player, messageData[tostring(player.userId)])
end)
end)
game.Players.PlayerRemoving:connect(function(player)
messageData[tostring(player.userId)] = nil
end)
The trigger: http://prntscr.com/8ur0s9 Chat Gui: http://prntscr.com/8ur0zp
local chatFrame = script.Parent.Frame
game.ReplicatedStorage.SendMessages.OnClientEvent:connect(function(messages)
chatFrame:ClearAllChildren()
for i, message in pairs(messages) do
local newLine = Instance.new("TextLabel", chatFrame)
newLine.Text = message
newLine.Size = UDim2.new(1,0,0,18)
newLine.Position = UDim2.new(0,0,0,18*(i-1))
newLine.TextXAlignment = Enum.TextXAlignment.Left
newLine.TextYAlignment = Enum.TextYAlignment.Center
newLine.BackgroundTransparency = 1
newLine.BorderSizePixel = 0
newLine.FontSize = Enum.FontSize.Size18
newLine.Font = Enum.Font.SourceSans
print(i .. ": " .. message)
end
end)

1 comment
When a player joins, you can use MarketplaceService:PlayerOwnsAsset(), and if it returns true, add tag