A way to get a specific word from text

Hello. I am trying to create a search bar, but for that I need the script to only get a specific part and proceed it as a variable, for example;

The script:

local y = string.lower(textBox.Text)
print(y)
if y == ‘roblox’ then
label.Text = ‘Roblox is a multiplayer platform for all ages.’

If a player types ‘roblox game’ instead of ‘roblox’ nothing triggers. Is there a way I can trigger if the keyword is close?

10 Likes

string:match() ?

https://developer.roblox.com/articles/string-patterns-reference

2 Likes

You can also check using string.find, which also has an option to not match using Lua patterns if you don’t need to.

4 Likes

You can use string.find:

local str = "Roblox is a cool game"
str = str:lower()

if str:find("roblox") then
   print("found it in string")
end
53 Likes