NPC Module erroring

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)

table.find(npcdialogue

All it needs is Wary[npcdialogue] to get the response from your dictionary

What you are currently using is the reason you are getting this error

1 Like

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

I fire it with these parameters:

("Wary", "1", false)

If it has the same error perhaps the name of your variable could be causin it to try to find

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

Try printing find after every time it changes, ive got a feeling its going to be nil no matter what

(If it doesnt error at the first one)
If it does change find

Doesn’t print anything, not even nil.

This line also brings out this error

		find = "Response"..num..""

attempt to concatenate boolean with string

You put responsr through as ‘false’ which is boolean, you cant combine that with string

That was when it was true, if it’s true, it would do “Response”…num…""
Also, I literally commented EVERYTHING out and it still errors somehow.

local Dialogue = {}
local Wary = {
	--["1"] = "wuzzerp",
	--["Response1"] = "Sup."
}
Dialogue.NPC = function(npc, num, response)
	local npcdialogue = nil
	print(npc)
	--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

Could it be how I fire it.?

Found out the issue. I have to fire the module passing the first argument as a table. Why is that.?