Finding a word within a TextLabel

How would I find a certain word within a TextLabel? I’m trying to run a function if the word ‘Elevator’ is found within a TextLabel.

local text = game.Workspace.TestPart.SurfaceGui.TextLabel.Text

newWord = newWord:lower(game.Workspace.TestPart.SurfaceGui.TextLabel.Text)

if newWord:find("elevator") then
	print("found in string")

You would add .text to the end of the textlabel. So newWord would be:

newWord = newWord:lower(game.Workspace.TestPart.SurfaceGui.TextLabel.text)

Apologies, I forgot to add .Text in the Test Script I wrote for this post (It is in the actual script used).

Here is my current Output error:

You should use string.lower() and string.match() for this. :lower and :find can’t be used on strings, because strings themselves don’t have methods like that. Check those out on the API reference on the devhub.

1 Like
local text = game.Workspace.TestPart.SurfaceGui.TextLabel.Text

newWord = string.lower(text)

if string.find(newWord, "elevator") then
	print("found in string")

:find() and :lower() aren’t valid methods


This worked, thank you for taking the time to rewrite the script!