For the past few hours, I’ve been trying to replicate a common element that MMOs have with their chat system. In most MMOs, the names of the items are in brackets with their rarity and you are open to hover them and/or click on them. Since I’m a fan of those systems, I’ve been trying to modify the default chat system DefaultChatMessage message creator module to allow that functionality from all messages that are sent from both the server and the player.
However, I’ve hit a wall and I can’t seem to actually progress forward on it. I’m currently adding spaces before the text in question to allow the message to be spaced out correctly. This works but it only works when you use a monspaced font, such as Code. Attached below are some pictures of it working with the Code font but not any other font:
Working:

Not working:

This is the current code that I have for the said functionality. Once I get it working, I’m going to design it to allow any item names to be used, not just “sword.”
-- this code is executed after the UpdateTextFunction function
local stringToLookFor = "[sword]"
if string.find(BaseMessage.Text, stringToLookFor) then
local beginPosition, endPosition = string.find(BaseMessage.Text, stringToLookFor, 1, true)
if not beginPosition or not endPosition then
return
end
local newString = string.gsub(BaseMessage.Text, "^[^%[]*", function(s)
return string.rep(" ", #s)
end, 1)
local tagColor = Color3.fromRGB(255, 255, 255)
local label = util:AddTagLabelToBaseMessage(BaseMessage, tagColor, newString)
label.Position = UDim2.new(0, 0, 0, 0)
end
Does anyone know how I can fix this problem?