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

I get an error with my NPC chat script and ModuleScript?

Asked by 4 years ago

I'm trying to make an NPC that chats but I get an error. Basically, it requires a ModuleScript and executes a function that gets the settings, and returns them back to the script.

Error: Argument 2 missing or nil

Chatting Script:

local ReplicatedStorage = game.ReplicatedStorage
local ChatService = game:GetService("Chat")

local Head = script.Parent.Head

local White = Enum.ChatColor.White
local Red = Enum.ChatColor.Red
local Green = Enum.ChatColor.Green
local Blue = Enum.ChatColor.Blue

local SettingsModule = require(ReplicatedStorage.Settings)
local Settings = SettingsModule:gs()

local Quotes = Settings[1]
local QuoteInterval = Settings[2]

function Chat(Part,Message,Color)
    ChatService:Chat(Part,Message,Color)
end

while wait(QuoteInterval) do
    Chat(Head,Quotes[math.random(1, #Quotes)],White)
end


Settings Script:

local quoteInterval = 4

local quotes = {
    "Hey!",
    "Hello!",
    "Hi!",
    "How are you?"
}


local gsFunction = {}
    function gsFunction:gs()
        return quotes, quoteInterval
    end
return gsFunction

Answer this question