Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
MemezyDev 172
3 years ago

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

Ad
Log in to vote
0
Answered by 3 years ago

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)
0
Thanks, I'll have to try that later! Wackyquacked 2 — 3y
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. Wackyquacked 2 — 3y

Answer this question