[HELP] cant get this loop to work

if I remove the loop and replace the [i] with a number from 1 to 5 it works fine, but the whole point of the loop is so I don’t have to write it 5 times the same code

edit: I have a global variable on top of the script named i

https://pastebin.com/GcUJ1dBJ

for i = 1, 5, 1 do
Citizen.CreateThread(function()
    local loc[i] = pos[i]
    pos[i] = garage_location[i]
    local blip = AddBlipForCoord(pos[i].entering[1],pos[i].entering[2],pos[i].entering[3])
    SetBlipSprite(blip,357)
    SetBlipColour(blip, 3)
    BeginTextCommandSetBlipName("STRING")
    AddTextComponentString('Dock')
    EndTextCommandSetBlipName(blip)
    SetBlipAsShortRange(blip,true)
    SetBlipAsMissionCreatorBlip(blip,true)
    checkgarage = 0
    while true do
        Wait(0)
        DrawMarker(1,pos[i].entering[1],pos[i].entering[2],pos[i].entering[3],0,0,0,0,0,0,4.001,4.0001,0.5001,0,155,255,200,0,0,0,0)
        if GetDistanceBetweenCoords(pos[i].entering[1],pos[i].entering[2],pos[i].entering[3],GetEntityCoords(LocalPed())) < 5 and IsPedInAnyVehicle(LocalPed(), true) == false then
            drawTxt('~g~E~s~ to open the menu',0,1,0.5,0.8,0.6,255,255,255,255)
            if IsControlJustPressed(1, 86) then
                MenuGarage()
                Menu.hidden = not Menu.hidden
                currentPos = garage_location[i]
            end
            Menu.renderGUI()
        end
    end
end)
end

1. That for loop will only execute 5 iterations. You never reset the index to 1. while loops while a certain condition or conditions are met - for will only loop for a number of iterations.
2. You’re creating a new thread with every iteration, which is completely unnecessary. You can and should instead move the for loop inside the thread.
3. Use a boolean variable to decide whether or not you should be running the for loop.

Maybe try something like this?

local shouldLoop = false

function DrawGarageMarkers()
	Citizen.CreateThread(function()
		if(shouldLoop) then
			while(shouldLoop) do
				Citizen.Wait(0)
				for i=1, 5 do
					DrawMarker(1, pos[i].entering[1], pos[i].entering[2], pos[i].entering[3], 0, 0, 0, 0, 0, 0, 4.001, 4.0001, 0.5001, 0, 155, 255, 200, 0, 0, 0, 0)
					if(GetDistanceBetweenCoords(pos[i].entering[1], pos[i].entering[2], pos[i].entering[3], GetEntityCoords(LocalPed())) < 5 and IsPedInAnyVehicle(LocalPed(), true) == false) then
						drawTxt('~g~E~s~ to open the menu', 0, 1, 0.5, 0.8, 0.6, 255, 255, 255, 255)
						if(IsControlJustPressed(1, 86)) then
							MenuGarage()
							Menu.hidden = not Menu.hidden
							currentPos = garage_location[i]
						end
						Menu.renderGUI()
					end
				end
			end
		end
	end)
end

function SetupBlips()
	for i=1, 5 do
		local loc[i] = pos[i]
		pos[i] = garage_location[i]
		local blip = AddBlipForCoord(pos[i].entering[1], pos[i].entering[2], pos[i].entering[3])
		SetBlipSprite(blip, 357)
		SetBlipColour(blip, 3)
		BeginTextCommandSetBlipName("STRING")
		AddTextComponentString('Dock')
		EndTextCommandSetBlipName(blip)
		SetBlipAsShortRange(blip, true)
		SetBlipAsMissionCreatorBlip(blip, true)
	end
	shouldLoop = true
	DrawGarageMarkers()
end

SetupBlips()