I am trying to make a module for NPC’s, but it is erroring whenever I try to fire and return a string. Here is what I am doing:
How I am firing it:
local module = require(game.ReplicatedStorage.Modules.NPCDialogue) local a = module.NPC("Wary", "1", false) print(a)
The module:
local Dialogue = {}
local Wary = {
["1"] = "wuzzerp",
["Response1"] = "Sup."
}
Dialogue.NPC = function(npc, num, response)
local npcdialogue = nil
if npc == "Wary" then
npcdialogue = Wary
end
print(num)
local find = num
if response then
find = response..num..""
end
if table.find(npcdialogue, find) then
return table.find(npcdialogue, find)
end
end
return Dialogue
It is erroring with this: ReplicatedStorage.Modules.NPCDialogue:11: invalid argument #1 to ‘find’ (table expected, got string)
It still is erroring with the same error as posted above, npcdialogue is the table itself. The variable find is what it is trying to look for (Response1 or just 1)
local Dialogue = {}
local Wary = {
["1"] = "wuzzerp",
["Response1"] = "Sup."
}
Dialogue.NPC = function(npc, num, response)
local npcdialogue = nil
if npc == "Wary" then
npcdialogue = Wary
end
print(num)
local find = num
if response then
find = "Response"..num..""
end
if npcdialogue[find] then
return npcdialogue[find]
end
end
return Dialogue
It’s something with the first parameter, setting the first parameter to nil will make it say
ReplicatedStorage.Modules.NPCDialogue:11: invalid argument #1 to ‘find’ (table expected, got nil), when the first parameter is just to set a different variable to a table