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

How can I do this?

Asked by 9 years ago

I'm trying to make a script that a model replies to a player when a player says something that has a certain keyword before, after, or both. Is it possible to do it that way?

local PlayerKeywords1 = {
    "yo",
    "ye",
    "hello",
    "hi",
    "wassup",
    "sup",
    "hellur",
    "ni hao",
    "hola",
    "hai"   
}
local PlayerKeywords2 = {
    "good",
    "g00d",
    "nice",
    "great"
}

local PlayerKeywords3 = {
    "uw0tm8",
    "u w0t m8",
    "y u",
    "wuv",
    "luv",
    "w0t",
    "w8",
    "fien"
}

local PlayerKeywords4 = {
    "pie",
    "food",
    "trains",
    "houses",
    "toilets",
    "power",
    "roblox",
    "robloxians",
    "celebrities",
    "people",
    "world",
    "youtube",
    "twitter",
    "ig",
    "instagram",
    "studio"
}

local PlayerKeywords5 = {
    "ikr",
    "i know right",
    "okay",
    "ok",
    "kk",
    "k",
    "kay",
    "kai",
    "what",
    "really",
    "crazy",
    "bad",
    "whet",
    "heh",
    "huh",
    "sorry"
}

local PlayerKeywords6 = {
    ":o",
    ":/",
    ";o",
    ";)",
    ";')",
    ":)",
    ";(",
    ";'(",
    ":(",
    ":3",
    "?",
    "?.?",
    "OoO",
    "O>O",
    "v.v",
    ">.>",
    "<.<",
    "(>^.^)>",
    "<(^.^<)",
    "^.^",
    ":I",
    ":|",
    "o.o",
    ":P",
    "xD",
    "XD",
    "xd",
    "c:",
    ":c",
    "c;",
    ";c",
    ";'c",
    "C:",
    "C;",
    "C;",
    "o-o",
}

local PlayerKeywords7 = {
    "bye",
    "bai",
    "cya",
    "see ya",
    "later",
    "peace",
    "dueces",
    "goodbye",
    "gudbye",
    "g00dbai",
    "goodbai",
    "gudbai",
    "g00dbye"
}
local Dialog1 = {
    "Wassup bruh?",
    "yeeee supppp",
    "Hello, mate!",
    "hi :3",
    "sup..",
    "Wassup... geez..",
    "What is that?",
    "I DUNT SPEAK YO LANGUAGE!!1!1!",
    "haiiii!!!"
}

local Dialog2 = {
    "Thank ya!",
    "Thanks!",
    "Thank you!",
    "You're great!"
}

local Dialog3 = {
    "i dunt want chu",
    "i dunt want chuuu",
    "w0t",
    "i wuv u 2",
    "i luv u 2",
    "w0t 2 u 2",
    "wait 4 w0t?",
    "thank chu!!1!1!"
}

local Dialog4 = {
    "I like pie!",
    "Ew food!",
    "Eh, trains arn't that bad..",
    "houses....house..HOUSE!!",
    "By the way, I need to go pee!!!",
    "I OVAP0W3R CHU!!",
    "Roblox is fun! But it gets boring after awhile",
    "I dunt knoe...",
    "I'm not a mainstream person..",
    "People.. I like people!",
    "Global warming is bad...",
    "Youtube, we broadcast everywhere!",
    "Follow me on twitter! I'm NoobyNoobCaiks!",
    "I rarely get on instagram... so.",
    "Roblox studio is a twist!"
}

local Dialog5 = {
    "I knoww",
    "I knowww",
    "mhm",
    "okay..",
    "Huh?",
    "Yes really.",
    "yeah ik u cray cray 2",
    "yah im badddd",
    "Yasss",
    "hehehehe c:",
    "*stares*",
    "It's okay! c:",
}

local Dialog6 = {
    "o-o",
    "I don't like faces!"
}

local Dialog7 = {
    "Goodbye!"
}

local DialogExtra = {
    "I don't understand you..",
    "ye okay *doesn't understand*",
    "Don't quite understand ya!",
    "What...",
    "Really? That language scares me...",
    "I understand bruh!!! *doesn't understand*",
    ">.> <.< *runs*",
    "So much weird languageeee",
    "Hey, I don't really understand."
}

function StartChat(Plr)
    for _,v in pairs(game.Workspace:GetChildren()) do
        if (v:IsA("Model")) then
            if v:findFirstChild("Humanoid") ~= nil then
                if v:findFirstChild("Torso") ~= nil then
                    if (script.Parent.Position - v:findFirstChild("Torso").Position).magnitude <= 5 then
                        Plr.Chatted:connect(function(msg)
                            if msg:lower():sub(1,2) == {PlayerKeywords1[4],msg}
                        end)
                    end
                end
            end
        end
    end
end

1 answer

Log in to vote
0
Answered by
yoshiegg6 176
9 years ago

Instead of using a bunch of if statements

if (v:IsA("Model")) then
if v:findFirstChild("Humanoid") ~= nil then
if v:findFirstChild("Torso") ~= nil then
if (script.Parent.Position - v:findFirstChild("Torso").Position).magnitude <= 5 then

You can just use

if v:IsA("Model") and v:findFirstChild("Humanoid") and v:findFirstChild("Torso") and script.Parent.Position - v:findFirstChild("Torso").Position).magnitude <= 5 then

You don't have to use if something ~= nil you can just use if (condition) then and you can put multiple conditions in one statement by using and. Try that, remove ends.

Ad

Answer this question