String matching a word

Hello Developers! I’m trying to do an automated PM, then the answer can be any answer but it should match a word to be correct, I will now answer these questions.

  1. What do you want to achieve? Keep it simple and clear!
    I want do an automated PM, which allows any answer with the matching word.
  2. What is the issue? Include screenshots / videos if possible!
    Is not saying “Correct.”, and I have a error, but I don’t know if is from that script: image
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Of course! I looked for sulutions on the Dev Hub, I tried searching in topics.

I want to do an automated PM, the PM allows any type of answer while the answer has the matching word, the problem is when I click “Send” it doesn’t says “Correct.”, I want do the PM match the word and reply with Correct.

I hope you can help me.

Kindest regards,
Waum_a.

local InputText = script.Parent.Parent.Roundify.Texthere.TextBox
local Question = script.Parent.Parent.Decoration.Question 
local match1 = string.match ("When not serving customers.", "customers")
         
script.Parent.MouseButton1Click:Connect(function()
	if InputText.Text == match1 then
	Question.Text = "Correct."
	end
end)

		
	

Also, it only matches when I say only “customers” and nothing else.

local InputText = script.Parent.Parent.Roundify.Texthere.TextBox
local Question = script.Parent.Parent.Decoration.Question
local Customers = "Customers"
         
script.Parent.MouseButton1Click:Connect(function()
	if InputText.Text == string.match("When not serving customers",Customers:lower()) then
	Question.Text = "Correct."
	end
end)

Tell me if it didn’t work.

Not working, image .

It only says Correct if you say “Customers” or “customers”, and nothing else like this: “customers”, Correct, “when im not serving customers”, doesn’t happens anything.

This is because string.match returns the string that you want to find. If you want to find the word “Bag” in a sentence, you can do so by writing out

local hi = string.match("I like 1 brown bag", "bag")

This will return “bag” if it has found the word in the string or return nil if the keyword is not there.

To make this work, try writing the following:

script.Parent.MouseButton1Click:Connect(function()
	if string.match(InputText.Text, "customers") ~= nil then
	     Question.Text = "Correct."
	end
end)
local InputText = script.Parent.Parent.Roundify.Texthere.TextBox
local Question = script.Parent.Parent.Decoration.Question
local Customers1 = "When not serving customers"
local Customers2 = "While serving customers"
script.Parent.MouseButton1Click:Connect(function()
	if InputText.Text == Customers1:lower() or Customers2:lower() then
		Question.Text = "Correct."
	end
end)

Maybe try this?

1 Like

This will always pass the condition since it checks if either InputText.Text is equal to Customers1:Lower() or if Customer2 is anything besides nil or false. Customer2 will never be nil or false, so it’ll always pass.

3 Likes