Issues with string.gsub second argument cause of magic characters

I’m writing a saving outfit system and i want to save the character outfit as a whole string however i’m having issues with the name part, since the custom name may have magic characters, if a player uses a name with magic characters and wants to change it again they can’t cause it has magic characters, is there any way to prevent it stopping?
I don’t really want to share the whole script so i’ll make an example:

local outfitstring=“ShirtID|PantsID|Robert[Sister:Jessica]”
local newname=“Tony<3”
print(string.gsub(outfitstring,string.split(outfitstring,"|")[3],newname))

i want it to print

ShirtID|PantsID|Tony<3

but since the old name has magic characters it can’t replace the part of the string and it prints

ShirtID|PantsID|Robert[Sister:Jessica] 0

1 Like

Not sure how would you be able to get around magic characters, you could try to remove all magic characters from the string before replacing the name or you could just not look for the name but the position in the string like this:

local outfitstring= "ShirtID|PantsID|Robert[Sister:Jessica]"
local newname= "Tony<3"

local newstring = string.split(outfitstring,"|")

newstring[3] = newname

print(table.concat(newstring,"|"))
1 Like

Thank you :D, i wish i knew table.concat before cause everything would have been easier lol

1 Like