Why does this run when anything is said and not the specific keywords?

Hey! Im wondering why when anything is said in the chat this runs. I have specific keywords set but it doesnt work and just runs when anything is said. Can someone help me with this issue?

Here is the code:
local RepStorage = game.ReplicatedStorage
local Scammers = RepStorage:WaitForChild(‘Scammer’)

local counter = 0

local ChatService = game:GetService('Chat')
local ScamBotMSGS = {
	'Hey! I heard your poor! Want some free ROUX?';
	'Hey my name is scammer. Im your friend. Go to www.ScamFreeRoux.com!';
	'You want free robux? Go to scam.com/roux!';
	'FAX! If you want to change that, fill out this servey.'
}

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg,r)
		if r then return end
		local lowermsg = string.lower(msg)
		
		if msg == 'im poor' or 'i need roux' or 'i need robux' or 'how to get free robux?' or 'im poor..' or 'can someone donate me robux?' then
			for i,v in pairs(Scammers:GetChildren()) do
				counter += 1
				Scammers.Parent = game.Workspace
				ChatService:Chat(Scammers.Head, ScamBotMSGS[math.random(1,#ScamBotMSGS)])
				Scammers.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
				wait(5)
				Scammers.Parent = RepStorage
				if counter == 5 then
					counter = 0
					break
				end
			end
		end
	end)
end)

EDIT: To be clear this is to get people to stop asking for robux in my games lol

You are using or improperly, you would need to write msg == "example string" or msg == "another example string".

2 Likes

It’s the way you;'re doing this I believe, I recommend making a table containing al lthe text you want it to check for in the Chatted event, like what you did for ScamBotMSGS, and just change that if statement to

if table.find(Inputs,msg)

Where Inputs is the name of the table that contains what a palyer shoudl say to run the code. The methods the others mentioned will work as well, but it’s simpler to make a table with all the text you want to check to simply the if statement

1 Like

the issue is with your if statement, you have:

if msg == 'im poor' or 'i need roux' or 'i need robux' or 'how to get free robux?' or 'im poor..' or 'can someone donate me robux?' then

whereas you should have

if msg == 'im poor' or msg == 'i need roux' or msg == 'i need robux' or msg == 'how to get free robux?' or msg == 'im poor..' or msg == 'can someone donate me robux?' then

this will check your msg variable against the strings, rather than just evaluating the strings themselves (which are not nil, and therefore will ‘pass’ the or test

2 Likes

This is also probably the most efficient method. And I will always be surprised by how fast people respond lol.

1 Like

Haha! That’s just the DevForum is sometimes! The benefit I mentioned for the table is so if you ever add even more text to check through, you wont have to add another condition in that statement which would impact the readability of that line, with a table however, you’d just have to add another string into it without changing the if statement at all! But again, everyone has their own way of making something, but it’s always best to do something efficient!

1 Like

Yep. I always try the most efficient methods, although they dont always go to plan lol

1 Like