Hi, I have these Chat tags for my game, and when I/Someone else talks in chat, they have the owner tag, How do I fix it?
local IDs = {111991246,337291338}
local CollabID = 1492603266
local ContributorIDs = {551973005}
local CreatorIds = {1631374761}
local GroupID = 32546712
local textChatService = game:GetService("TextChatService")
local player = game.Players.LocalPlayer
textChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
if message.TextSource then
if player:IsInGroup(32546712) then
properties.PrefixText = "<font color='#ffff00'>[Member]</font> " .. message.PrefixText
end
if player.UserId == 111991246 or player.UserId == 337291338 then
properties.PrefixText = "<font color='#800080'>[Owner ๐]</font> " .. message.PrefixText
end
if player.UserId == 551973005 then
properties.PrefixText = "<font color='#eb4b79'>[Contributer ๐จ]</font> " .. message.PrefixText
end
if player.UserId == 1631374761 then
properties.PrefixText = "<font color='#ff0000'>[Creator ๐ฅ]</font> " .. message.PrefixText
end
if player.UserId == 1492603266 then
properties.PrefixText = "<font color='#4900ff'>[Collaborator ๐]</font> " .. message.PrefixText
end
end
return properties
end
Iโm assuming this would be an issue with the or conditional. Iโm not a big fan of or conditionals myself, and Iโd much rather use a table to store the ownerโs UserIds.
You seem to already have the IDs stored as local IDs = {111991246,337291338}, so we can work with that.
Maybe give this a try?
local IDs : {number} = {111991246, 337291338}
-- Inside the .OnIncomingMessage function:
if table.find(IDs, player.UserId) ~= nil then -- This will check to see if the player's UserId is in the IDs table.
properties.PrefixText = "<font color='#800080'>[Owner ๐]</font> " .. message.PrefixText
end
Hey, something I just noticed with your code is that youโre using LocalPlayer for .OnIncomingMessage, when you should actually be using TextSource. If you use LocalPlayer (or in your case, itโs a variable assigned to local player) itโll be running a check for every single Player instead of TextSource, who is the player that actually sent the message.
So instead, your code should be looking like this, which may actually be the reason as to why your code wasnโt functioning correctly earlier.
local IDs : {number} = {111991246, 337291338}
-- Inside the .OnIncomingMessage function:
if table.find(IDs, TextSource.UserId) ~= nil then -- This will check to see if the player's UserId is in the IDs table.
properties.PrefixText = "<font color='#800080'>[Owner ๐]</font> " .. message.PrefixText
end
You should take care to apply this same logic to every single UserId check in this code.
To boot, I would suggest using the return keyword within each if statement you have there. This prevents any possible overriding cases that may occur when you have multiple prefixes like this, and in particular, the group check. I would also order these most-to-least important, like this:
-- Basic sample,
-- the "return" statement stops the rest of the branches from being checked
if player.UserId == 111991246 or player.UserId == 337291338 then
properties.PrefixText = "<font color='#800080'>[Owner ๐]</font> " .. message.PrefixText
return properties
end
if player.UserId == 1631374761 then
properties.PrefixText = "<font color='#ff0000'>[Creator ๐ฅ]</font> " .. message.PrefixText
return properties
end
if player.UserId == 551973005 then
properties.PrefixText = "<font color='#eb4b79'>[Contributer ๐จ]</font> " .. message.PrefixText
return properties
end
if player.UserId == 1492603266 then
properties.PrefixText = "<font color='#4900ff'>[Collaborator ๐]</font> " .. message.PrefixText
return properties
end
if player:IsInGroup(32546712) then
properties.PrefixText = "<font color='#ffff00'>[Member]</font> " .. message.PrefixText
return properties
end
(Small edit, I see that youโre doing concatenation here to support multiple prefixes, but I feel this may be unnecessary? Clutters up chat sometimes) @gelvinware does also give good advice on how to simplify this.
As for the issue, I believe this stems from your use of player. In your code, you mark it at the beginning of your script as the LocalPlayer:
local player = game.Players.LocalPlayer -- ln. 12
Instead, use the TextSource.UserId property to get the proper sender. This would explain why you saw everyone with the owner tag.
Assuming that this is you and you are the owner of the game, then of course everybody will have the owner tag.
To fix this, remove this line and replace the main function with this:
textChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
local player = game.Players:GetPlayerByUserId(message.TextSource.UserId)
if player then
if player:IsInGroup(32546712) then
properties.PrefixText = "<font color='#ffff00'>[Member]</font> " .. message.PrefixText
end
if player.UserId == 111991246 or player.UserId == 337291338 then
properties.PrefixText = "<font color='#800080'>[Owner ๐]</font> " .. message.PrefixText
end
if player.UserId == 551973005 then
properties.PrefixText = "<font color='#eb4b79'>[Contributer ๐จ]</font> " .. message.PrefixText
end
if player.UserId == 1631374761 then
properties.PrefixText = "<font color='#ff0000'>[Creator ๐ฅ]</font> " .. message.PrefixText
end
if player.UserId == 1492603266 then
properties.PrefixText = "<font color='#4900ff'>[Collaborator ๐]</font> " .. message.PrefixText
end
end
return properties
end
I used every method in this forum, so im not sure who actually solved the problem, but iโll give you the solution for basically mentioning all the problems, thank you all though!