Best method to find text with letters that match a word (;invs = ;invisible)

Apologies for the confusing wording, I wasn’t too sure what this type of function is usually referred to as

I’ve been trying to create my very own admin system to learn things like string patterns, and I’m stumped on one thing.

Let’s say the player types “inv” or “invs.” I want a script to find if the text they type has letters that are part of a certain word to make the proper command function without having the player type the whole word.

I’ve been trying to figure out what type of string manipulation I should use. So far, I’ve tried string.match and string.find, however, neither have worked.

Here’s some placebo code to put it into Lua language:

local Word = "invisible"

local TextPlayerTyped = "invs" -- Of course, this would be a text box input, however for demonstration purposes I'm just making this a string variable

if string.something(Word, TextPlayerTyped) then
    print("Invisible!")
end

Thank you in advance!

string.match and string.find don’t work here because you are trying to find “invs” inside “invisible”
invisible starts with “invis” not “invs”

That was a typo on my end.

However, this doesn’t solve my issue. Even if the player were to type “invis” it still doesn’t function.

local Word = "invisible"
local TextPlayerTyped = "invis"

if string.match(Word, TextPlayerTyped) then
    print("Invisible!")
end

if string.find(Word, TextPlayerTyped) then
    print("Invisible!")
end

I got both of these to print, do you want something else?

I was actually just about to delete my reply and mark your solution before you replied!

The reason it didn’t work when I tried it was due to the way I set up the textbox on my end. Apologies for the misinformation.

1 Like