I’ve run into an issue where, while trying to make a chat bot, the bot won’t chat back when I type a message. To be clear, I’m making a filter with tables to see if the message includes one of the filters and will return a chat message from the bot like “Well, thank you! [Insert player name] .” if the player compliments the bot. Problem is that it wont chat back no matter what I do. Could really use some help on this script:
local function isGreeted()
chat:Chat(script.Parent.Parent.Head, "Greetings,"..player.Name, Enum.ChatColor.Blue)
print("M.A.P has succesfully greeted with "..player.Name..".")
greeted = true
interacted = true
end
local function isComplimented()
chat:Chat(script.Parent.Parent.Head, "Well, Thank you, "..player.Name, Enum.ChatColor.Green)
print("M.A.P has succesfully greeted with, "..player.Name..".")
greeted = true
interacted = true
end
local function readMessage(msg) --Im so smart
if msg then
local msgsplitted = string.split(msg, ",")
local spaced = string.split(msg, " ")
local numberedWords = #spaced
local msgsplittedNumbered = #msgsplitted
if msg == true then
for i = 1, #greetings do --first word
local msgcorrect = string.lower(msgsplitted[1])
if msgcorrect == greetings[i] then
isGreeted()
print("greeted by"..player.Name)
end
end
for i = 1, #compliments do --first word
local msgcorrect = string.lower(msgsplitted[1])
if msgcorrect == compliments[i] then
isComplimented()
print("complimented by "..player.Name)
end
end
end
else
print("huh how")
end
end
player.Chatted:Connect(readMessage)
local function isGreeted()
chat:Chat(script.Parent.Parent.Head, "Greetings,"..player.Name, Enum.ChatColor.Blue)
print("M.A.P has succesfully greeted with "..player.Name..".")
greeted = true
interacted = true
end
local function isComplimented()
chat:Chat(script.Parent.Parent.Head, "Well, Thank you, "..player.Name, Enum.ChatColor.Green)
print("M.A.P has succesfully greeted with, "..player.Name..".")
greeted = true
interacted = true
end
local function readMessage(msg) --Im so smart
if msg then
local msgsplitted = string.split(msg, ",")
local spaced = string.split(msg, " ")
local numberedWords = #spaced
local msgsplittedNumbered = #msgsplitted
for i = 1, #greetings do --first word
local msgcorrect = string.lower(msgsplitted[1])
if msgcorrect == greetings[i] then
isGreeted()
print("greeted by"..player.Name)
end
end
for i = 1, #compliments do --first word
local msgcorrect = string.lower(msgsplitted[1])
if msgcorrect == compliments[i] then
isComplimented()
print("complimented by "..player.Name)
end
end
else
print("huh how")
end
end
player.Chatted:Connect(readMessage)
local function isGreeted()
chat:Chat(script.Parent.Parent.Head, "Greetings,"..player.Name, Enum.ChatColor.Blue)
print("M.A.P has succesfully greeted with "..player.Name..".")
greeted = true
interacted = true
end
local function isComplimented()
chat:Chat(script.Parent.Parent.Head, "Well, Thank you, "..player.Name, Enum.ChatColor.Green)
print("M.A.P has succesfully greeted with, "..player.Name..".")
greeted = true
interacted = true
end
local function readMessage(msg) --Im so smart
local msgsplitted = string.split(msg, ",")
local spaced = string.split(msg, " ")
local numberedWords = #spaced
local msgsplittedNumbered = #msgsplitted
for i = 1, #greetings do --first word
local msgcorrect = string.lower(msgsplitted[1])
if msgcorrect == greetings[i] then
isGreeted()
print("greeted by"..player.Name)
end
end
for i = 1, #compliments do --first word
local msgcorrect = string.lower(msgsplitted[1])
if msgcorrect == compliments[i] then
isComplimented()
print("complimented by "..player.Name)
end
end
end
player.Chatted:Connect(readMessage)
It works after I put it in replicated storage, I thought the solution was to add a localscript in replicated storage and another script in server script service and use a remote function but this is so much simpler, thanks a lot!