Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I check if one of the values in an if statement is true?

I'm trying to make a game where there's an NPC and if you say nice things to it, it will shrink. I want it so that there is multiple words that it will accept. I also want it so that you have to include the word in a message, not have to type out only the exact word. I've made some code for this but it only works if you use the first value, "cool". Can someone help me fix this? Thanks!

game.Players.PlayerAdded:connect(function(player)
		player.Chatted:connect(function(msg)
			if string.match(string.lower(msg), "cool" or "epic" or "rad" or "coolest" or "fan" or "small" or "fun" or "funny") then
			print("OK 3")
			ChatService:Chat(part, "O_O", "White")
			local Humanoid = model.Humanoid
			if Humanoid then
				local HS = Humanoid.HeadScale
				local BDS = Humanoid.BodyDepthScale
				local BWS = Humanoid.BodyWidthScale
				local BHS = Humanoid.BodyHeightScale

				HS.Value = HS.Value - 0.1
				BDS.Value = BDS.Value - 0.1
				BWS.Value = BWS.Value - 0.1
				BHS.Value = BHS.Value - 0.1
				print("Shrunk!")
			end
			end
		end)
	end)

2 answers

✓ Accepted answer

split the message with string.split(message, " "), and put that inside of a variable. then use a for loop since that returns a table and then check if the word is the activator word. if it is make a value true or something idk. if this worked plz accept answer ty

Doing an or statement for each word is very inefficient, a good way to check words is to make an array containing the words and loop through that array checking if the word matches. Example:

local Words = {"cool","epic","rad","coolest","fan","small","fun","funny"} --Words

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(msg)
		for _,Word in pairs(Words) do
			if string.match(string.lower(Word),msg) then
				ChatService:Chat(part, "O_O", "White")
				local Humanoid = model.Humanoid
				if Humanoid then
					local HS = Humanoid.HeadScale
					local BDS = Humanoid.BodyDepthScale
					local BWS = Humanoid.BodyWidthScale
					local BHS = Humanoid.BodyHeightScale

					HS.Value = HS.Value - 0.1
					BDS.Value = BDS.Value - 0.1
					BWS.Value = BWS.Value - 0.1
					BHS.Value = BHS.Value - 0.1
					print("Shrunk!")
				end
			end
		end
	end)
end)

2 comments

0

Thanks, I'll have to try that later!

0

There are two problems with this code. The first one is when I say "cool" in chat, it runs the code twice. And the second problem is that if I used the words in a sentence (for example, "ur rad") the code will not run. I also renamed Words to niceWords because I'm planning on making it so that when you say something mean the person grows.

This discussion is preserved as it was. New answers, comments, and votes are closed.