Reset function

I need my function to fully reset every time I run it, but for some reason it doesn’t (It’s probably because of my table ‘letters’ but IDK how to fix it) If I interrupt it with a new drawnpctext then it stops drawing the last sentence but it doesn’t start a new one.
Same if I don’t interrupt and I let it run through, it still doesn’t draw the new text. I know a quick and dirty fix, I could make all the functions non local set them to nil every time… But that is a horribly messy way of coding, does anyone know a better fix?

		local function drawnpctext(text)

	local textlen2 = nil
	local NPCChat = vgui.Create( "DLabel", MyDerma )
	local letters = {}
	local textlen = string.len( text )+1
	local npctextbin = nil

	if not textlen2 then
		textlen2 = 1
		local sound = CreateSound( LocalPlayer(), "buttons/button18.wav" )

			sound:PlayEx( 0.2, 150 )

			local npctextbin = string.byte(text, textlen2, textlen2+1)

			table.insert(letters, npctextbin)

			textlen2 = textlen2+1
			NPCChat:SetText( string.char( unpack(letters) ) )
			NPCChat:SetSize (ScrH()/2,100)


local textintro = [[It's not easy living as a BRAINS...
			 Oops, I meant burn victim* in this town.
			 The amount of terror I go through on a daily basis 
			 is beyond comprehension for you living folks.
			 I meant clear skin folk! Dangit... I suck at this!]]


I think the problem is that you never removed the previously created DLabel (from what I can see)

[editline]16th April 2016[/editline]

Wait, nevermind, I didn’t notice you were changing it… hang on…

[editline]16th April 2016[/editline]

Try using

string.sub rather than using string.byte and then string.char

Can’t use string.sub :confused: first value has to be lower than the second value using string.sub, I want that flipped, only way I found to this is using my method.
I used string.sub first because I am more familiar with it, but it makes my text render from back to start (instead of start to finish) and I didn’t find a way around that using string.sub. Any other ideas?

-bump- I still don’t have a fix

-bump 2- I’m sure someone can point me in the right direction, I am not a very skilled programmer, my code is by no means advanced.