Text in table^3 won't typewrite

What I’m trying to do is making a modified version of a NPC Dialog System in Toolbox, so that when you interact with a NPC, you get different dialogs. Now, I know where I went wrong, but I don’t know how to fix it (haven’t coded in a long time)

SCRIPT1 (local script):

function inDialog(ChosenPath, Dialog, Number, Enabled)
	if Enabled then
		if Dialog[ChosenPath] then
			print(ChosenPath)
			if ChosenPath[Number] then
				print(ChosenPath[Number])
				typeWrite(ChosenPath[Number])
			end
		end
	else
		print("Conversation Ended.")
	end
end

SCRIPT2 (module script):

local NPCModule= {
	["Test"] = {
		Path1 = {
			"blah blah test.",
			"blah blah test.",
			"blah blah test."
		},
		Path2 = {
			"blah blah test.",
			"blah blah test.",
			"blah blah test."
		},
		Path3 = {
			"blah blah test.",
			"blah blah test.",
			"blah blah test."
		},
		Path4 = {
			"blah blah test.",
			"blah blah test.",
			"blah blah test."
		},
	}
}

return NPCModule

I’ve tested the script multiple times with prints, yet it doesn’t work. No errors, surprisingly.

2 Likes

where do you call the function

each time i click a text button.

Have you tried this approach on the function ?

function inDialog(ChosenPath, Dialog, Number, Enabled)
    if Enabled then
        local ChosenPathDialog = Dialog[ChosenPath]
        if ChosenPathDialog then
            local ChosenDialog= ChosenPathDialog[Number]
            if ChosenDialog then
                print(ChosenDialog)
                typeWrite(ChosenDialog)
            end
        end
    else
        print("Conversation Ended.")
    end
end
-- i also assume you got a typewrite function somewhere

& is this how you call the function?

inDialog(ChosenPath, NPCModule["Test"], Number, Enabled)
 -- assuming u got number & enabled somewhere idk & the module required of course
1 Like

I’ll try out that method. If it works, I’ll reply.

And for this, I basically have a math.random as the ChosenPath to basically randomize the chances, Dialog is basically the NPC’s dialogs, Number is the 1st - 3rd message, Enabled is basically there to turn on or off the inDialog

So it didn’t work. I honestly don’t know what the problem is to be honest. I know where I went wrong, I just can’t pinpoint it.

Here’s the text activation if you want to figure out what in the world I did wrong

text.Activated:Connect(function()
		if not debounce then
			debounce = true
			NPC_Amount += 1
			task.wait(1)
			debounce = false
		end	
		if typeWriting then
			return
		end
		
		local NPCNAME = npcModule[NPC_Value.Value]
		inDialog(Random_Dialog, NPCNAME, NPC_Amount, true)
	end)

bumping the thread y’all!!!???!!!

Alright update! So the prints work now, I just changed something within the tables. Now it has this error.

Haha, me being silly again. I completely forgot to add the Text value to the inDialog function so that I can reference it to the typeWrite.

Now it legit won’t type :grin:

It finally works! Thanks for the help y’all :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.