I have a part called "Checkpoint2", and inside it, there is a script with this function
print(string.gsub(script.Parent.Name, "Checkpoint", ""))
called when Touched
.
It should print "2" , shouldn't it? too bad, cause it prints "2 1" and I have no idea why... I've tried to make a second string.gsub
to remove the " 1" , but then it prints "2 0" ! Can someone see an error here? (the rest of the script is useless)
gsub
actually returns two things. First the string, and then how many times it did the replace.
print
prints all things returned, so you're seeing both, separated by a tab.
There isn't an error here at all! If you store it to a variable, you'll see that it works normally:
local str, matches = script.Parent.Name:gsub("Checkpoint","") print(str) -- 2 print(matches) -- 1 (the other number you're seeing)