local marketplaceservice = game:GetService("MarketplaceService")
local gamepass = 225576408
local textChatService = game:GetService("TextChatService")
textChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
if message.TextSource then
local player = game:GetService("Players"):GetPlayerByUserId(message.TextSource.UserId)
local plr = game.Players.LocalPlayer
-- if marketplaceservice:UserOwnsGamePassAsync(plr.UserId, gamepass) then
if plr.Name == "Player1" then -- this is to test in the local server
properties.PrefixText = "<font color='#00ffee'>[VIP]</font> " .. message.PrefixText
end
end
return properties
end
(local script)
This is my VIP script in starterplayerscripts, the if player.Name == “Player1” is just for a test in the local servers.
Im wondering why it only displays the chat tag for Player1 and not Player2 and how can I make a serverscript for this.
To create a server script for a VIP chat tag using TextChatService and not Legacy on Roblox, follow these steps: 1. Open Roblox Studio and create a new script in the ServerScriptService. 2. Import the TextChatService module by adding the following line at the top of your script:
lua
local TextService = game:GetService("TextService")
Create a function to handle player chatting and apply the VIP chat tag. You can use the OnPlayerChat event to listen for incoming chat messages. Here’s an example function:
lua
local function onPlayerChat(player, message)
-- Check if the player has VIP status
if player:GetRankInGroup(123456) >= 2 then -- Replace 123456 with your VIP group ID and 2 with the required VIP rank
-- Create the VIP chat tag
local vipTag = "[VIP] "
-- Modify the message to include the VIP chat tag
local taggedMessage = vipTag .. message
-- Filter the tagged message
local filteredMessage = TextService:FilterStringAsync(taggedMessage, player.UserId):GetChatForUserAsync(player.UserId)
-- Return the filtered message to be displayed
return filteredMessage
end
-- Return the original message if the player is not VIP
return message
end
Connect the OnPlayerChat event to the function you created. Add the following line of code after the onPlayerChat function:
lua
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local filteredMessage = onPlayerChat(player, message)
if filteredMessage then
TextService:FilterStringAsync(filteredMessage, player.UserId):GetChatForUserAsync(player.UserId)
end
end)
end)
Save the script and test it in-game. Players with VIP status in the specified group will have their chat messages tagged with “[VIP]” before being sent, while non-VIP players’ messages will remain unaffected. Remember to replace 123456 with your actual VIP group ID and 2 with the required VIP rank in the onPlayerChat function.
Doesnt seem to work, is the code supposed to be like:
SSS script
local TextService = game:GetService("TextService")
local function onPlayerChat(player, message)
-- Check if the player has VIP status
if player:GetRankInGroup(32857374) >= 2 then -- Replace 123456 with your VIP group ID and 2 with the required VIP rank
-- Create the VIP chat tag
local vipTag = "[VIP] "
-- Modify the message to include the VIP chat tag
local taggedMessage = vipTag .. message
-- Filter the tagged message
local filteredMessage = TextService:FilterStringAsync(taggedMessage, player.UserId):GetChatForUserAsync(player.UserId)
-- Return the filtered message to be displayed
return filteredMessage
end
-- Return the original message if the player is not VIP
return message
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local filteredMessage = onPlayerChat(player, message)
if filteredMessage then
TextService:FilterStringAsync(filteredMessage, player.UserId):GetChatForUserAsync(player.UserId)
end
end)
end)
Hey there!
You State that your Chat Tag only appears for Player1, This would be due to you getting muddled with your “plr” and “player” Variables you have!
(Simple answer is that you don’t need the “plr” Variable and that when checking the player’s name you should use your “player” Variable), You can Read Below on a Pretty Simple way on Making a VIP Chat Tag work though!
As for checking if a player is VIP and giving them a Chat Tag, I’d recommend using Attributes (Since you can’t Check if a User Owns a Gamepass through MarketplaceService on Client.)
Here’s an Example!
Server Script:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
Players.PlayerAdded:Connect(function(player)
player:SetAttribute("Vip", false) --Default
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) then
player:SetAttribute("Vip", true)
end
end)
Client Script:
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
TextChatService.OnIncomingMessage = function(Message)
local Properties = Instance.new("TextChatMessageProperties")
if Message.TextSource then
local player = Players:GetPlayerByUserId(Message.TextSource.UserId)
if player:GetAttribute("Vip") == true then
Properties.PrefixText = "<font color='#00ffee'>[VIP] </font> "..Message.PrefixText
end
end
return Properties
end
you need to set Properties’ Text because its nil
local TextChatService = game:GetService("TextChatService")
TextChatService.OnIncomingMessage = function(Message)
local Properties = Instance.new("TextChatMessageProperties")
if Message.TextSource then
local player = Players:GetPlayerByUserId(Message.TextSource.UserId)
if player:GetAttribute("Vip") == true then
Properties.PrefixText = "<font color='#00ffee'>[VIP] </font> "..Message.PrefixText
end
end
Properties.Text = Message.Text
return Properties
end
I Must’ve missed out on getting the “Players” Service. (Apologies for that)
With the Players Service it should look Something like this…
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
TextChatService.OnIncomingMessage = function(Message)
local Properties = Instance.new("TextChatMessageProperties")
if Message.TextSource then
local player = Players:GetPlayerByUserId(Message.TextSource.UserId)
if player:GetAttribute("Vip") == true then
Properties.PrefixText = "<font color='#00ffee'>[VIP] </font> "..Message.PrefixText
end
end
return Properties
end