How can I get the gsubbed version of a value without changing the value?

Hello! I am trying to get the gsubbed version of a string without changing the original string. Let me Explain

local newval = repstr.OwnedPets:WaitForChild(forusecurrentplayerid).Value
local gsubbednewval = newval:gsub("%-","")

basically I am trying to get the gsubbed version of a string and store it in a variable without changing the original string value.

Your code does not change the stringvalue instance if thats what you asked.

1 Like

yes, thats what I am aiming for

As far as I remember, if you assign a value/property to a variable, changing that value will not modify the original value.

I set up a simple test, with the below code:

local name = script.Parent.Name

local newName = name:gsub("e", "o")
print("Name: "
print("New Name: "..newName)

The name variable afterwards still reads Test, while the newName variable reads Tost. Like what Nacht said, the original variable/property is not changed.

hmm, then problem must be elsewhere. Ty :slight_smile:

1 Like