Told the script to stop when table becomes nil but it kept going anyway

I ran checks to stop the script from going further when the table’s value became nil, but it kept going anyway after checking

if type(txt) == "string" then
        text(Dialogue, txt)
    elseif type(txt) == "table" then
        local turn = 1
        repeat -- keep running until no more dialogs are left
            if not txt[turn] then return end
            text(Dialogue, txt[turn])
            turn += 1
            task.wait(#txt[turn] * 0.020)
        until not txt[turn]
    end

Try using a for loop instead of looping through it with a repeat

for i,v in pairs(TABLE) do

end

It still throws the same error

Solved, i just had to compare the turn to the amount of table.

Fixed version:

if type(txt) == "string" then
		text(Dialogue, txt)
	elseif type(txt) == "table" then
		local turn = 1
		for i,v in pairs(txt) do
			text(Dialogue, txt[turn])
			turn += 1
			if turn > #txt then break end
			task.wait(#txt[turn] * 0.020)
		end
	end

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