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)
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)