Changing a portion of the text on a string value

today i just made a “Traits” system which is a bunch of text cramped into a single string value to prevent making the data folder look messy, using “:find()” i can check if the string value contains something like “Injured” but i recently ran into an issue of not being able to replace/remove a part of the text without replacing the entire string value, any suggestions on how to get around this?

You should try turning it into a table instead using split: like this

local sliceup = "stuff in the string1/stuff in the string2/ stuff in the string3"
local maketable = sliceup:split"\n"
--to get the table
return maketable

I haven’t tested it yet though

1 Like

it doesnt work, not to mention that datastores are currently failing for me and making this way harder

You can use split,

string.split(string,pattern)

local newStr = string.split("I'm on DevForum\nSay hello", "\h") -- returns {"I'm on DevForum","Say hello"}

You could use string.gsub

String.Gsub
Returns a copy of s in which all (or the first n, if given) occurrences of the pattern have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred.

An example usage would be

local String = 'Hello!'
local toReplace = 'Hello'
local replaceWith = 'Goodbye'

String = string.gsub(String, toReplace, replaceWith)

print(String)
> Goodbye!
5 Likes

thanks alot its actually finally working, you’re a lifesaver :+1:

2 Likes