Automatic Reply System, why is it not working?

Hello,
I’m working on a automatic reply system. Could someone help me fixing the lua code? Maybe i messed it up with client- and server-side.
Code:

questions = {
	"write all in small letters",
	"don't use question mark (?)",
	"seperated by commas",
	"this is question NR. 4"
}

answers = {
	"This is the answer to question NR. 1 set above.",
	"Use small and big letters.",
	"Set a point (.) at the end.",
	"This is the answer to question NR. 4 set above."
}

AddEventHandler("chatMessage", function(Source, Name, Msg)
	local line = 0
	local nope = 0
	for quest in questions do
		local line = line + 1
		if(string.find(string.lower(quest), string.lower(Msg))) then 		
			Notify(answer[line])
			Notify("This may not be the answer you're looking for.")
			CancelEvent()
		else 
			local nope = nope + 1
		end
	end
	if(nope == table.getn(questions)) then
		TriggerClientEvent("chatMessage", -1, Name, { 255, 255, 255 }, Msg)
	end
end)

function Notify(text)
    SetNotificationTextEntry('STRING')
    AddTextComponentString(text)
    DrawNotification(false, true)
end

Hold on, is this a client code or server code?

If its server you cant have this function

function Notify(text)
    SetNotificationTextEntry('STRING')
    AddTextComponentString(text)
    DrawNotification(false, true)
end

but if its client you cant trigger a client event from the client using TriggerClientEvent

:confused:

@BigYoda It’s a client script. So do i have to replace TriggerClientEvent with TriggerEvent?

Yes and remove source.

@zee So it should look like this?

questions = {
	"write all in small letters",
	"don't use question mark (?)",
	"seperated by commas",
	"this is question NR. 4"
}

answers = {
	"This is the answer to question NR. 1 set above.",
	"Use small and big letters.",
	"Set a point (.) at the end.",
	"This is the answer to question NR. 4 set above."
}

AddEventHandler("chatMessage", function(Name, Msg) 
	print("Message detected.") --just for testing
	local line = 0
	local nope = 0
	for quest in questions do
		local line = line + 1
		if string.find(string.lower(quest), string.lower(message)) then 		
			Notify(answer[line])
			Notify("This may not be the answer you're looking for.")
			CancelEvent()
		else 
			local nope = nope + 1
		end
	end
	if nope == table.getn(questions) then
		TriggerEvent("chat:addMessage", -1, pname, { 255, 255, 255 }, message)
	end
end)

function Notify(text)
    SetNotificationTextEntry('STRING')
    AddTextComponentString(text)
    DrawNotification(false, true)
end

Any other mistake? I’m learning LUA, came from C#. But i don’t like coding FiveM Scripts in C#.

By remove I mean remove. Not change.

@zee remove what?

The -1 in TriggerEvent. Not source, my bad.

@zee ok thanks :wink:
So this should work like that?

questions = {
	"write all in small letters",
	"don't use question mark (?)",
	"seperated by commas",
	"this is question NR. 4"
}

answers = {
	"This is the answer to question NR. 1 set above.",
	"Use small and big letters.",
	"Set a point (.) at the end.",
	"This is the answer to question NR. 4 set above."
}

AddEventHandler("chatMessage", function(Source, Name, Msg) 
	print("Message detected.") --just for testing
	local line = 0
	local nope = 0
	for quest in questions do
		local line = line + 1
		if string.find(string.lower(quest), string.lower(Msg))) then 		
			Notify(answer[line])
			Notify("This may not be the answer you're looking for.")
			CancelEvent()
		else 
			local nope = nope + 1
		end
	end
	if nope == table.getn(questions) then
		TriggerEvent("chat:addMessage", Name, { 255, 255, 255 }, Msg)
	end
end)

function Notify(text)
    SetNotificationTextEntry('STRING')
    AddTextComponentString(text)
    DrawNotification(false, true)
end

Perhaps. I’m just telling you the correct params for that native.

Can you also stop mentioning me? Thanks.

Hmm even the print does not work. Is maybe the event “chatMessage” wrong?