#Issue with chat tags

1 messages · Page 1 of 1 (latest)

solid epoch
#

I have a very good idea of chat tags but for some reason I just cant get this right. It replaces the players name.


local MarketplaceService = game.MarketplaceService
local ReplicatedStorage = game.ReplicatedStorage
local TextChatService = game.TextChatService
local Players = game.Players

local event = ReplicatedStorage:WaitForChild("TagEvent")

TextChatService.OnIncomingMessage = function(message)
    if not message.TextSource or not message.TextSource.UserId then
        return
    end
    
    local properties = Instance.new("TextChatMessageProperties")

    local plr = Players:GetPlayerByUserId(message.TextSource.UserId)
    if not plr then return end

    print("Made it past checks")

    local tags = {}

    if plr:GetAttribute("VIP") then
        table.insert(tags, "VIP")
    end

    if plr:GetAttribute("Donator") then
        table.insert(tags, "Donator")
    end

    if #tags == 1 then
        local tag = "["..tags[1].."]"
        properties.PrefixText = "["..tags[1].."]"
    elseif #tags == 2 then
        properties.PrefixText = "["..tags[1].."] ["..tags[2].."]"
    end
    
    return properties
end

solid epoch
#

replaces my name

rain moss
rain moss
solid epoch
rain moss
solid epoch
rain moss
solid epoch
rain moss
#

just work with me on this - so it's not fine because it shouldn't be replacing your username, yes?

solid epoch
rain moss
#

so.. how can your code be both fine and not fine at the same time? schrodinger's script? wot

delicate loom
#

can u just help the guy?

#

golly

solid epoch
rain moss
delicate loom
#

i am here for help to but just cus someone dosent know how code workds dosent mean u gotta be rude about it

rain moss
#

"my code is fine, but it's also not working" is a factual impossibility. the first step to fixing your code is accepting that it is not fine.

delicate loom
#

ngl ur reminding me of a dad whos teaching his son a leson bc he stole a piece of candy

rain moss
#

if you want to call that rude, well, idk what to tell you 🤷

delicate loom
#

ok i apoligize rude was taking it too far

solid epoch
rain moss
#

like if you put a capital where you shouldn't, that can break things. if you leave out some small punctuation, it can break things

solid epoch
delicate loom
#

cosmic thinks the code is fine but he dosent know if it is or isnt so hes asking if the the code is wrong or something else is wronng is that right?

#

oh i type slow mb

solid epoch
rain moss
rain moss
delicate loom
#

thats not ture i made a menu but it didnt work because it didnt have the same parent as the button to open it so in that case it wouldnt be the code

solid epoch
rain moss
#

you couldn't ask for an easier process of this reduction - just take the docs-given working code. under most other circumstances, you have to remove stuff from your code until you get down to the crux of it

solid epoch
rain moss
# solid epoch I am not spending another hour rewriting it. I just want to know why it went wro...

here's what i did. i took the example from the docs, and added one line: print(message.PrefixText). that would not have taken you an hour. ```lua
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
print("prefix text:",message.PrefixText)
local textSource = message.TextSource
if textSource then
local player = Players:GetPlayerByUserId(textSource.UserId)
if player then
if player:GetAttribute("IsVIP") == true then
local overrideProperties = Instance.new("TextChatMessageProperties")
overrideProperties.PrefixText = "[VIP] " .. message.PrefixText
return overrideProperties
end
end
end

return nil

end```

#

this snippet is purely the docs code + the print i added.

#

i threw it in a localscript in starterplayerscripts and checked the output.

#

not so hard this debugging this now is it?

#

and when i read the output, would you look at that. it's my name!!

solid epoch
#

My system is much different then this

silk jungleBOT
#

studio** You are now Level 15! **studio

rain moss
rain moss
#

and the reason why i'm focusing on this is because if you don't learn how to do that, you are going to have a hard time coding in the future. reliance on asking for help is not practical in the long term.

#

so instead of just giving you an answer, i showed you how to reach the answer for yourself.

solid epoch
#

alr

rain moss
#

if you want to consider that rude, well, not much more i can do to help you short of doing everything for you like i did by giving you the answer just now 🤷

#

coz believe it or not, giving out direct answers without showing how i came to that answer, is not helpful. it just makes you more and more dependent on asking for help instead of solving your own problems sad

rain moss
solid epoch
#

I actually just cant spot whats wrong. Is there any ways I can improve or.

rain moss
#

well i hope you have learned at least one new technique today for debugging. reduce the problem. take existing working code and compare it to yours, look for the smaller details, always print your outputs. never assume you know what the code is doing. always check what it is actually doing via prints or breakpoints etc

#

coz a simple print of the prefixtext before and after you change it would have answered your question before you asked it ;o