Problem with create a array index

Hello,
i have problem with create a array index.

text = {}

Citizen.CreateThread(function()
	while true do
        Citizen.Wait(0)

        if #text > 0 then

		    local p = GetGameplayCamCoords()

	        for i, ii in pairs(text) do--for all existing 3d text draw it
	        	--print(i .. " text=" .. text[i].text)
				local onScreen, _x, _y = World3dToScreen2d(text[i].x, text[i].y, text[i].z)
			    local distance = GetDistanceBetweenCoords(p.x, p.y, p.z, text[i].x, text[i].y, text[i].z, 1)

				if onScreen and distance < text[i].dist then
			        SetTextScale(0.0, 0.35)
			        SetTextFont(0)
			        SetTextProportional(1)
			        SetTextColour(text[i].color[1], text[i].color[2], text[i].color[3], 255)
			        SetTextDropshadow(0, 0, 0, 0, 255)
			        SetTextEdge(2, 0, 0, 0, 150)
			        SetTextDropShadow()
			        SetTextOutline()
			        SetTextEntry("STRING")
			        SetTextCentre(1)
			        AddTextComponentString(text[i].text)
			        DrawText(_x,_y)
			    end
			end
		end
	end
end)

function CreateText(x, y, z, color, text, dist)
	print("CreateText")
    print(x)
    print(y)
    print(z)
    print(color)
    print(text)
    print(dist)
    for i=1,#text+1 do
    	print(i)
    	if text[i] == nil then
    		text[i] = {}--create a new 3d text into table
			text[i].x = x
			text[i].y = y
			text[i].z = z
			text[i].color = color
			text[i].text = text
			text[i].dist = dist
			return true
		end
    end
end

and error:

[     62484] Error running call reference function for resource texts: citizen:/scripting/lua/scheduler.lua:405: @texts/client.lua:47: attempt to index a string value (local 'text')

error line is “text[i] = {}”

Thanks for any help