String gets mistaken as a table somehow

I’m trying to make an npc chat text strings I listed in a module to make a dialog

The strings in the tables are not strings but are somehow tables. I don’t see them as tables, but the script does. Its giving me the error
Workspace.QuestSandBox.QuestScript:20: invalid argument #2 (string expected, got table).

Ive tried doing unpack(), but then, it tells me its a string. Im confused at this point.

QuestScript (the script that gets the module)

local QuestDetails = require(script.Parent.QuestDetails)
local QuestLine = QuestDetails.text.QuestLine
local QuestNPCs = QuestDetails.speakers.QuestNPCs

function Chat(head,msg,color)
	game:GetService("Chat"):Chat(head, msg, color)
end


local dh = script.Parent.Dummy.Humanoid

function StartDiolog()
	local hasFired = false
	if hasFired then return end
	hasFired = true
	for i, val in pairs(QuestLine) do
		wait(1)
		print(val.speaker)
		print(val.txt)
		Chat(script.Parent[val.speaker], val.txt, Enum.ChatColor.White)
		local sound = game.Workspace.QuestLineNotifications[QuestNPCs[val.speaker]]:Clone()
		-- make sound parent speakers head
		sound.Parent = script.Parent[val.speaker].Head
		sound:Play()
	end

end

script.Parent.PAD.Touched:Connect(function()
	StartDiolog()
end)

QuestDetails (Module that gets required)

local module1 = {
	QuestNPCs = {
		["Dummy"] = {
			DialogSound = "frostilism"
		};
	};

}

local module2 = {
	QuestLine = {
	txt1 = {
		txt = "Hello world! This is a test message.";
		speaker = module1.QuestNPCs.Dummy
	};
	txt2 = {
		txt = "This works!";
		speaker = module1.QuestNPCs.Dummy
	};
	txt3 = {
		txt = "This works. Im happy to know! And im mr dummy man! See ya!";
		speaker = module1.QuestNPCs.Dummy
	};
 }
};

local module = {
	speakers = module1;
	text = module2
}

return module

Any help is appreciated. Thanks!

what are the table values


txt is clearly a table, it’s erroring because it’s a table

It doesnt look like to me. I don’t understand.

try replacing this with

script.Parent:FindFirstChild(val.speaker.name)

note that the “name” property may not exist and it’s “Name” instead

the txt variables inside the txt# tables on QuestDetails

You are trying to require this from what I see, and you’re putting it in the {}, thus making it a table

What im saying is the “txt = “Hello world! This is a test message”” is supposed to be a string. Is the code bringing up something different?

That error occurs when you try to index an instance with a table
image

It probably is getting something wrong

function Chat(head,msg,color)
	print(msg, "BALLS")
	game:GetService("Chat"):Chat(head, msg, color)
end

change the function to the code above, then what does it say

1 Like

from what i see, he fires ChatService:Chat, but the second argument is appearantly a table. so i think it got nothing to do with instance indexing.

This could also be the case but from what I’m seeing, OP is trying to index script.Parent with val.Speaker (a table from module1). If they were to replace the second argument val.txt with just a raw string such as "test", it would make it clear if it is the index error or something else

3 Likes

that’s another issue, but this thread is talking about the chatservice issue.

Ill check out your responses later. Have a great day.

What your saying is probably not right. it might not be chat service, but a in-formatted table/string. again, have a great day. :slightly_smiling_face:

im clearly right, it’s an argument issue so it has to do with the Chat function.

the Chat function is literally piping the arguments to ChatService:Chat, so i’m correct.

this is happening becuase as @Dede_4242 said you are calling the whole table and this is why you got this error, to fix this you simply need to tell the script which variable you want from this table in our case its txt, also why u assigning the table to another variable when you can just use same table with different Variables in one table?

local NPc_Chat = {

["QuestNPCs"] = {
		["Dummy"] = {
			DialogSound = "frostilism"
		};
	};
["QuestLine"] = {
txt1 = {
		txt = "Hello world! This is a test message.";
		speaker = module1.QuestNPCs.Dummy
	};
	txt2 = {
		txt = "This works!";
		speaker = module1.QuestNPCs.Dummy
	};
	txt3 = {
		txt = "This works. Im happy to know! And im mr dummy man! See ya!";
		speaker = module1.QuestNPCs.Dummy
	};
}

}
return NPc_Chat

in the Main Script:

local QuestLine = QuestDetails["QuestLine"]["txt1"].txt --"Hello world! This is a test message."
-- to get the speaker of txt1:
local QuestNPCs = QuestDetails["QuestLine"]["txt1"].speaker

did you reply to the wrong person? because @Dede_4242 did not respond to me at all.

1 Like

he did:

You are trying to require this from what I see, and you’re putting it in the {}, thus making it a table

1 Like