How to find exact word in a string

? That isn’t my goal with it haha. I want the background to turn red/white, not the text.

U know that string.sub is deleting a text from … to …, U should rather do an string.sub( #button.Name/2 , #button.Name)

This works in normal Lua. Could you try it out in ROBLOX studio for me? I don’t have access at the moment.

local function HasWholeWord(str, word) 
    return string.find(str, "%f%w" .. word .. "%f%W") ~= nil
end

print(HasWholeWord("hello world", "hell"))  -- false
print(HasWholeWord("hello world", "hello")) -- true

Edit: If that doesn’t work because ROBLOX doesn’t support frontier patterns, this should:

local function HasWholeWord(str, word)
    return string.find(str, "^" .. word .. "$") ~= nil -- match exact
        or string.find(str, "^" .. word .. "%W") ~= nil -- match start to non-alphanumeric
        or string.find(str, "%W" .. word .. "$") ~= nil -- match non-alphanum to end
        or string.find(str, "%W" .. word .. "%W") ~= nil -- match non-alphanum to non-alphanum
end

print(HasWholeWord("hello world", "hell"))  -- false
print(HasWholeWord("hello world", "hello")) -- true
print(HasWholeWord("hello", "hello")) -- true
print(HasWholeWord("hell", "hello")) -- false
print(HasWholeWord("world hello", "hello")) -- true

Edit 2: If you want underscores to count as the same word you can do that too by replacing %w with [%w_] and %W with [^%w_]. What I posted defines a “word” as just a string of alphanumeric characters. So "hello_world" would be two words.