While using string.find, I encountered a bug where it would fail to find a pattern in a TextLabel if there is a “-” then another letter/number in the pattern it’s trying to find. This happens on the current ROBLOX studio version. I think the gifs should explain it better.
Please post the exact case where string.find is returning unexpected results in your opinion (one line of code, make sure to include the line of code here in text, not as image so we can copy it easier).
What are the values of v.Frame.TextLabel.Text, plr, and bote in the case where it does unexpected things? Please give us a self-contained test case so that I can just copy the line in studio and I can see what you mean. (I can’t do this with this line at the moment, it’s not a self-contained example.)
Whatever you pass as the “to be found” thing in string.find is interpreted as a string pattern. For string patterns, there are special characters with a special meaning, so if you stick these characters in your “to be found” string, it won’t work as expected because they are not interpreted as the plain text.
The special character in your case is the ‘-’. To escape this special character in your string pattern, you simply need to put an escape character, which is the %, in front of it. Example:
print(string.find("Damage caused - Derp-A(person)", "Derp%-A")) -- note % before -
Which gives the output you wanted:
17 22
The % is not actually part of the search string. All it does is say “hey, please interpret the character after this as a plaintext character, and not as a special character”.
Also a nice thing is that string.find has a 4th argument (“3rd” if using str:find()):
print(("a-b"):find("a-")) --> "a"
--('a-' means 'find at least 1 a, but more is ok I guess'
print(("a-b"):find("a-",1,true)) --> "a-"
-- That true is the 'plain' argument, which, when true, disables patterns
-- Now it's literally looking for 'a-' byte by byte, not using it as a pattern
-- (Just added that 1 (which is the default value) as 'plain' comes after it)