If String.Find is always true?

Inside this script I notice that no matter what the string always proceeds to work with function.

Greetings = {
	"Hello",
}

	for _, v in pairs(Greetings) do
		if string.find(text, v) then
			print('yes')
			createchat('ai', Greetings[math.random(1,#Greetings)])
		end
	end

Not sure, you give no definition of what ‘text’ is. So if ‘text’ is “Hello”, “H”, “E”, even “”, then we have defined behaviour!

1 Like

Here is a full definition of text:

local function searchlistai(text)
	for _, v in pairs(Greetings) do
		if string.find(text, v) then
			print('yes')
			createchat('ai', Greetings[math.random(1,#Greetings)])
		end
	end
end

local function onFocusLost(enterPressed)
	if enterPressed then
		createchat('plr', ChatBox.Text)
		searchlistai(ChatBox.Text)
	end
end

Can you tell me what you put in Chatbox?

1 Like

thats what I had before, but I don’t think it works either. Also The logic would be funny. The first string is the text your searching in and the second one is the text to be found . Since I am repeating this sequence because of the table. It shouldn’t work that way.

When I do it this way it passes through no matter what. Creating a yes print for every table value it surfs through.
image

Can you tell me what you put in Chatbox?

1 Like

I put hello each time, and it is one of the 27 values I have. The single value I had earlier was just so it looked less messy.

Thats what I did, I showed you it goes through every single time when I do that.

image

I try this and Output is : none

1 Like

wth is going on then? do you want the full code

If you ok then I’m ok too (Sorry if I’m so nervous right now I didn’t sleep yet lol)

1 Like

Thats alright, it’s late for me too.

local plrs = game:GetService('Players')
local lp = plrs.LocalPlayer
local ChatBox = script.Parent
local replicatedstorage = game:GetService('ReplicatedStorage')
local ManageFrame = script.Parent.Parent
local msgcloner = script.Parent.Parent.MsgCloner
tbl1 = nil
tbl2 = nil
tbl3 = nil
local UIS = game:GetService('UserInputService')
local tweenservice = game:GetService('TweenService')

Greetings = {
	"Hello",
	"Hi",
	"hello",
	"hi",
	"Hola",
	"hola",
	"yo",
	"Yo",
	"Hi!",
	"hi",
	"Howdy",
	"howdy",
	"Greetings",
	"greetings",
	"hey",
	"Hey",
	"Good Day",
	"G'day",
	"good day",
	"g'day",
	"Gday",
	"gday",
	"Good day",
	"Good morning",
	"good morning",
	"Good Morning",
	"Good mornin",
}

MoodStateQues = {
	"Hru",
	"hru",
	"how are you",
	"How are you",
	"HOWAREYOU",
	"Mood Check",
	"mood check",
	"Hows it",
	"How's it",
	"hows it",
	"how's it",
	"how is it",
	"What's up",
	"whats up",
	"Whats up",
	"WHATS UP",
	"WSP",
	"wsp",
	"Wsp",
	"How's your day",
	"How is your day",
	"how's your day",
	"how is your day",
	"How are you lately",
	"how are you lately",
	"How you been",
	"how you been",
	"How have you been doing",
	"how have you been doing",
}

MoodStateResp = {
	"I'm good",
	"Im good",
	"I am good",
	"Pretty good thanks",
	"pretty good thanks",
	"pretty snazzy",
	"im great!",
	"Feeling good",
	"feelin' good",
	"lmao good thanks",
}

troll = {
	"cheese grater",
	"amogus",
}

trollresp = {
	"same",
	"I agree",
	"fard?"
}

--International English Base Word Directory--

local function createchat(origin, text)
	for _, v in pairs(msgcloner:GetChildren()) do
		local msgpieces = v:Clone()
		local msgbase = msgcloner:Clone()
		wait()
		msgbase.Parent = ManageFrame
		msgpieces.Parent = msgbase
		msgbase.BackgroundTransparency = 0.2
		msgbase.TextTransparency = 0
		msgbase.Name = "ChatClone"
		
		if origin == "ai" then
			for _, v in pairs(ManageFrame:GetChildren('ChatClone')) do
				if v:IsA('TextLabel') then
					v.Position = v.Position - UDim2.new(0,0,0.15,0)
				end
			end
			msgbase.Position = UDim2.new(0.028, 0, 0.692, 0)
			msgbase.Text = text
			ChatBox.Text = ""
		else
			for _, v in pairs(ManageFrame:GetChildren('ChatClone')) do
				if v:IsA('TextLabel') then
					v.Position = v.Position - UDim2.new(0,0,0.15,0)
				end
			end
			msgbase.Position = UDim2.new(0.653, 0, 0.692, 0)
			msgbase.Text = text
			ChatBox.Text = ""
		end
	end
end

local function searchlistai(text)
	for _, v in pairs(Greetings) do
		if string.find(v, text) then
			print('yes')
			createchat('ai', Greetings[math.random(1,#Greetings)])
		end
	end
	----------------------------------------------------------
	for _, v in pairs(MoodStateQues) do
		if string.find(v, text) == true then
			print('yes')
			createchat('ai', MoodStateResp[math.random(1,#MoodStateResp)])
		end
	end
	----------------------------------------------------------
	for _, v in pairs(troll) do
		if string.find(v, text) then
			print('yes')
			createchat('ai', trollresp[math.random(1,#trollresp)])
		end
	end
end

local function onFocusLost(enterPressed)
	if enterPressed then
		createchat('plr', ChatBox.Text)
		searchlistai(ChatBox.Text)
	end
end

ChatBox.FocusLost:Connect(onFocusLost)

I tried this on web so IDK If it’s work in game I can’t test in studio right now sorry :frowning:

local function searchlistai(text)
	for _, v in pairs(Greetings) do
		if string.find(text, v) then
			print('yes Greet')
			--createchat('ai', Greetings[math.random(1,#Greetings)])
   return
		end
	end
	----------------------------------------------------------
	for _, v in pairs(MoodStateQues) do
		if string.find(text, v) == true then
			print('yes Mood')
			--createchat('ai', MoodStateResp[math.random(1,#MoodStateResp)])
			return
		end
	end
	----------------------------------------------------------
	for _, v in pairs(troll) do
		if string.find(text, v) then
			print('yes troll')
			--createchat('ai', trollresp[math.random(1,#trollresp)])
			return
		end
	end
	
	print("None of these")
end
1 Like

what is the return for exactly?

I just want to make sure if that found then not continue finding

image
image

Im not sure if you double dashed the createchat function for a reason but I removed dashes.

You do it right :smiley: I didn’t add createchat in to my test I think that script is alright

1 Like

Can you try this pls

local function searchlistai(text)
	for _, v in pairs(Greetings) do
		if string.find(text, v) then
			print('yes Greet')
			createchat('ai', Greetings[math.random(1,#Greetings)])
			return
		end
	end
	----------------------------------------------------------
	for _, v in pairs(MoodStateQues) do
		if string.find(text, v) == true then
			print('yes Mood')
			createchat('ai', MoodStateResp[math.random(1,#MoodStateResp)])
			return
		end
	end
	----------------------------------------------------------
	for _, v in pairs(troll) do
		if string.find(text, v) then
			print('yes troll')
			createchat('ai', trollresp[math.random(1,#trollresp)])
			return
		end
	end
	
	print("None of these")
end

Still getting none of these in the script. I need to note in the last script you sent it printed every viable answer for moodrequest

I removed to print every answer for moodrequest

try close script and try again It may didn’t save

1 Like