Attempted to index string with 'text'

My script currently works, however once the player walks away and returns it as the title issue.

The script working:
Place1 - Roblox Studio (gyazo.com)

The script breaking:
Place1 - Roblox Studio (gyazo.com)

The entire script breaks after this, nothing happens if I try to click to continue dialogue and nothing happens if I walk away (It should disappear if I do.)
I am completely at a loss.

local function typewrite(object,text,length)
	for i = 1,#text,1 do 
		object.Text = string.sub(text,1,i)
		wait (length)
	end
end

Here is the function I call to write.

cd.MouseClick:Connect(function(Player)
	plr = Player
	busy = true
	billboard.Enabled = true
	if dialogueprog == 1 then
		if deb == false then
			deb = true 
			typewrite(text, "Are you sure you want to switch to Dagger Style?", speechtime)
			dialogueprog = 2
			wait(speechtime)
			deb = false
		end
	else
		if dialogueprog == 2 then
			if deb == false then
				deb = true 
				typewrite(text, "Walk away if you do not.", speechtime)
				dialogueprog = 3
				wait(speechtime)
				deb = false
			end
		else
			if dialogueprog == 3 then
				if deb == false then
					deb = true 
					typewrite(text, "Giving Style", speechtime)
					dialogueprog = 1
					givetool()
					wait(speechtime)
					deb = false
				end
			end
		end
	end
end)

Here is the part of the script with the text.

local text = script.Parent.Parent.Head.BillboardGui.Frame.TextBox
local frame = script.Parent.Parent.Head.BillboardGui.Frame
local billboard = script.Parent.Parent.Head.BillboardGui
local cd = script.Parent.Parent.DiaBox.ClickDetector
local plr
local function typewrite(object,text,length)
	for i = 1,#text,1 do 
		object.Text = string.sub(text,1,i)
		wait (length)
	end
end
local dialogueprog = 1
local busy = false
local deb = false
local speechtime = 0.01

local function givetool()
	local clo = game.ServerStorage.Weapons.Dagger:Clone()
	for i, v in pairs (plr.Backpack:GetChildren()) do
		if v:IsA("Tool") then
			v:Destroy()
		end
	end
	for i, v in pairs (clo:GetChildren()) do
		if v:IsA("Script") then
			v.Enabled = true
		end
		if v:IsA("LocalScript") then
			v.Enabled = true
		end
	end
	clo.Parent = plr.Backpack
	script:Destroy()
end

cd.MouseClick:Connect(function(Player)
	plr = Player
	busy = true
	billboard.Enabled = true
	if dialogueprog == 1 then
		if deb == false then
			deb = true 
			typewrite(text, "Are you sure you want to switch to Dagger Style?", speechtime)
			dialogueprog = 2
			wait(speechtime)
			deb = false
		end
	else
		if dialogueprog == 2 then
			if deb == false then
				deb = true 
				typewrite(text, "Walk away if you do not.", speechtime)
				dialogueprog = 3
				wait(speechtime)
				deb = false
			end
		else
			if dialogueprog == 3 then
				if deb == false then
					deb = true 
					typewrite(text, "Giving Style", speechtime)
					dialogueprog = 1
					givetool()
					wait(speechtime)
					deb = false
				end
			end
		end
	end
end)

while true do
	if busy == true then
		while true do
			local mag = (plr.Character.Torso.Position - script.Parent.Parent.Torso.Position).Magnitude
			if mag<13 then
			else
				billboard.Enabled = false
				text = ("Placeholder")
				busy = false
				dialogueprog = 1
				deb = false
			end 
			wait(.5)
		end
	end
	wait(.5)
end

And to whom it may concern, here is the full script.

It may be because of this

Check the type of object before

Code
local text = script.Parent.Parent.Head.BillboardGui.Frame.TextBox
local frame = script.Parent.Parent.Head.BillboardGui.Frame
local billboard = script.Parent.Parent.Head.BillboardGui
local cd = script.Parent.Parent.DiaBox.ClickDetector
local plr
local function typewrite(object,text,length)
	if typeof(object) == "Instance" and object:IsA("TextLabel") then
		for i = 1,#text,1 do 
			object.Text = string.sub(text,1,i)
			task.wait(length)
		end
	end
end

local dialogueprog = 1
local busy = false
local deb = false
local speechtime = 0.01

local function givetool()
	local clo = game.ServerStorage.Weapons.Dagger:Clone()
	for i, v in pairs(plr.Backpack:GetChildren()) do
		if v:IsA("Tool") then
			v:Destroy()
		end
	end
	for i, v in pairs(clo:GetChildren()) do
		if v:IsA("Script") then
			v.Enabled = true
		end
		if v:IsA("LocalScript") then
			v.Enabled = true
		end
	end
	clo.Parent = plr.Backpack
	script:Destroy()
end

cd.MouseClick:Connect(function(Player)
	plr = Player
	busy = true
	billboard.Enabled = true
	if dialogueprog == 1 then
		if deb == false then
			deb = true 
			typewrite(text, "Are you sure you want to switch to Dagger Style?", speechtime)
			dialogueprog = 2
			task.wait(speechtime)
			deb = false
		end
	else
		if dialogueprog == 2 then
			if deb == false then
				deb = true 
				typewrite(text, "Walk away if you do not.", speechtime)
				dialogueprog = 3
				task.wait(speechtime)
				deb = false
			end
		else
			if dialogueprog == 3 then
				if deb == false then
					deb = true 
					typewrite(text, "Giving Style", speechtime)
					dialogueprog = 1
					givetool()
					task.wait(speechtime)
					deb = false
				end
			end
		end
	end
end)

while true do
	if busy == true then
		while true do
			local mag = (plr.Character.Torso.Position - script.Parent.Parent.Torso.Position).Magnitude
			if mag<13 then
			else
				billboard.Enabled = false
				text = ("Placeholder")
				busy = false
				dialogueprog = 1
				deb = false
			end 
			task.wait(.5)
		end
	end
	task.wait(.5)
end

You can also separate the variable

Code
local frame = script.Parent.Parent.Head.BillboardGui.Frame
local billboard = script.Parent.Parent.Head.BillboardGui
local cd = script.Parent.Parent.DiaBox.ClickDetector
local plr

local typewrite_object = script.Parent.Parent.Head.BillboardGui.Frame.TextBox
local text
local function typewrite(Text,length)
	for i = 1,#Text,1 do 
		typewrite_object.Text = string.sub(Text,1,i)
		task.wait(length)
	end
end

local dialogueprog = 1
local busy = false
local deb = false
local speechtime = 0.01

local function givetool()
	local clo = game.ServerStorage.Weapons.Dagger:Clone()
	for i, v in pairs (plr.Backpack:GetChildren()) do
		if v:IsA("Tool") then
			v:Destroy()
		end
	end
	for i, v in pairs (clo:GetChildren()) do
		if v:IsA("Script") then
			v.Enabled = true
		end
		if v:IsA("LocalScript") then
			v.Enabled = true
		end
	end
	clo.Parent = plr.Backpack
	script:Destroy()
end

cd.MouseClick:Connect(function(Player)
	plr = Player
	busy = true
	billboard.Enabled = true
	if dialogueprog == 1 then
		if deb == false then
			deb = true 
			typewrite("Are you sure you want to switch to Dagger Style?", speechtime)
			dialogueprog = 2
			task.wait(speechtime)
			deb = false
		end
	else
		if dialogueprog == 2 then
			if deb == false then
				deb = true 
				typewrite("Walk away if you do not.", speechtime)
				dialogueprog = 3
				task.wait(speechtime)
				deb = false
			end
		else
			if dialogueprog == 3 then
				if deb == false then
					deb = true 
					typewrite("Giving Style", speechtime)
					dialogueprog = 1
					givetool()
					task.wait(speechtime)
					deb = false
				end
			end
		end
	end
end)

while true do
	if busy == true then
		while true do
			local mag = (plr.Character.Torso.Position - script.Parent.Parent.Torso.Position).Magnitude
			if mag<13 then
			else
				billboard.Enabled = false
				text = ("Placeholder")
				busy = false
				dialogueprog = 1
				deb = false
			end 
			task.wait(.5)
		end
	end
	task.wait(.5)
end

Thank you! It was that line, I decided to just remove it. And thank you for the quick response.