UserInputService returning nil for QTE System

I have a Quick Time Event module that you have to press correct keys in a specific order that is laid out in a table, but when I call the function twice, I get an error saying the key the player must press is nil.

It works by updating the key the player must press to BindToRenderStep and unbinds when the key is wrong, the player runs out of time, or when it reaches the end of the table.

Does anyone know what’s going on?

Error:

Module Script snippet:

local result

function QTES.ShowQTE(period, keys)
	
	if playing == true then
		warn("Cannot interupt current QTE. Please wait until this QTE is finished.")
		return
	end

	local bindname = "QTETimer"
	local oldperiod = period
	local db = false
	local count = 1
	local currentkey = keys[count]
	local fail = false
	
	-- Start init QTES
	playing = true
	
	-- Create visual key icons for player to press
	CreateKeys(keys)

	
	print("Amount of keys:", #keys)

	
	-- Clear Visual Keys
	local function clearKeys()
		for _,v in pairs(QTEmenu.QTE_order:GetChildren()) do
			if v:IsA("ImageLabel") then v:Destroy() end
		end
	end
       
	-- Frame Check: Unbind if failed, when time runs out, or when currentkey = nil
	RS:BindToRenderStep(bindname, Enum.RenderPriority.Input.Value - 1, function(delta)
		period -= delta
		QTEmenu.Timer.bar.Size = UDim2.new(period/oldperiod,0,0.9,0)
	
		currentkey = keys[count]
		print("Current Key = ", currentkey)
		
		-- success case
		if currentkey == nil then 
			RS:UnbindFromRenderStep(bindname)
			QTEmenu.Enabled = false
			playing = false
			
			clearKeys()
			result = true 
		end
		
		-- fail case
		if period <= 0 or fail == true then
			QTEmenu.Timer.bar.Size = UDim2.new(0,0,0.9,0)
			RS:UnbindFromRenderStep(bindname)
			failedAnimation()
			QTEmenu.Enabled = false
			playing = false
			
			clearKeys()
			result = false
		end
	end)
	
	
	UIS.InputEnded:Connect(function(key)
		
		if playing == true and db == false and key.UserInputType == Enum.UserInputType.Keyboard then
			if key.KeyCode ~= Enum.KeyCode[currentkey] then
				db = true	
				fail = true
				failedAnimation()
				clearKeys()
				db = false
			elseif key.KeyCode == Enum.KeyCode[currentkey] then
				print(count)
				db = true
				count += 1
				wait(0.1)
				db=false
			end
		end
	end)
	
end

Local Script:

local result
QTES = require(script.Parent)

case = QTES.ShowQTE(4, {"Z","Z","Z"})
wait(5)
print("Running function again...")
QTES.ShowQTE(4, {"Z","M","N"})

Edit: I should probably leave the RBXL file. Sorry about that.
QTE_Testing.rbxl (40.5 KB)