Trying to access a value inside multiple tables/dictionaries

I’m trying to set a textbox’s text to quotes.Vinnie.Speech.Hey!, however it’s not working properly and I’m not sure how to fix it, or how to format it to make it work.

Heres the code, it works fine if I index it very manually, but now when I try to index it like shown below.

script.Parent.Dialogue.Text = quotes[NPC.Name].Speech[1] -- this gives me Players.anthlons.PlayerGui.Interface.NPC.QuestControl:93: attempt to index nil with 'Speech' error
local quotes = {
	["Vinnie"] = {
		["Speech"] = {
			"Hey!",
			"Bye!",
		};
		["Questions"] = {
			["Speech"] = "Do you need me to repeat the Speech?"
		};
	};	
}

However if I do

print(quotes.Vinnie.Speech[1])

… in the developer console it works completely fine.

Thanks!

Is NPC.Name exactly Vinnie? That might be the cause of the error.

2 Likes

Yes, it goes through quotes.Vinnie but I can’t access speech. ← Nvm whoops

I had him named tutorial agh, I feel so stupid. :man_facepalming: Sorry for wasting your time, can’t believe I didnt see that!