How to make strings safe to put in the editor for all characters

I am currently making a plugin, and in a portion of the code it uses GUI text, and I can’t trust the user to escape their own characters, so:
How can I take Text out of a GuiObject and make it safe for the script editor? For example:

Gui text: "Welcome to the game, “PlayerName!”
Script editor equivalent: "Welcome to the game, "PlayerName"!" -- error at the second string

I think what you want is to use quotation marks inside of strings?
What about:

local String = 'Welcome to the game, "playerName"!'

Does this work?
Or do you want to join strings?

local String = "Welcome to the game, "..player.Name.."!"

Sorry I am not too sure what you want :frowning:

You could add a backslash for every character that you want to escape
If your strings are in double quotes, then you can do something like this

local str = '"Hello"'
print(str:gsub("\"", "\\\"")) -- \"Hello\"
1 Like

Thank you, but I couldn’t do this manually as it’s automatically coming in from a random gui object text.