Settimera() crash game

Hello, I know this is horribly wrong, I will change it later, but what am I doing bad with Timera(), because at this state it freezes the game forever, no, wait, actually only while it will crash… Can anyone help me please?

function count()
    timer = 3
    Settimera(0)
    local t1
    while(timer ~= 0) do
        t1 = Timera()
        while (Timera() - t1) < 1000 do
            SetTextColour(currentrace.Color.r,currentrace.Color.g,currentrace.Color.b,255)
            SetTextScale(1.5, 1.5)
            SetTextFont(0)
            SetTextProportional(0)
            SetTextEntry("STRING")
            AddTextComponentString(tostring(timer))
            DrawText(0.6,0.5)
        end
        timer = timer-1
    end
    t1 = Timera()
    while (Timera() - t1) < 2000 do
        SetTextColour(currentrace.Color.r,currentrace.Color.g,currentrace.Color.b,255)
        SetTextScale(1.5, 1.5)
        SetTextFont(0)
        SetTextProportional(0)
        SetTextEntry("STRING")
        AddTextComponentString("GO!")
        DrawText(0.6,0.5)
    end...

When calling natives into a while loop you need to call Wait(0) else, FiveM will freeze.

1 Like

Ok, i’ve changed it since then, but now it’s looping on first while forever, and Timera() have still value 0. I’m clearly pepega in this. Could you help me?


RegisterCommand("test", function(source, args)
	timer = 3
	Settimera(0)
    while(timer ~= 0) do
		print("Timer has been setted up")
        while (Timera() < 1000) do
			text(timer,0.7,0.5,255,0,0,1.5)
			print("Timera at the end of the loop was:"..Timera())
			Wait(0)
		end
		print("Timer has value: "..timer)
        timer = timer-1
        Wait(0)
	end
	Settimera(0)
    while (Timera() < 2000) do
        text("GO!",0.7,0.5,255,0,0,1.5)
		Wait(0)
	end
	PlaySoundFrontend(-1, "FLIGHT_SCHOOL_LESSON_PASSED", "HUD_AWARDS")
end)
function text(content, x, y, r, g, b, scale)
	SetTextColour(r,g,b,255)
	SetTextScale(scale, scale)
	SetTextFont(0)
	SetTextProportional(0)
	SetTextEntry("STRING")
	AddTextComponentString(content)
	DrawText(x, y)
end

Unsure if intrinsic script timers work here - manual subtracting of a start time from GetGameTimer should be equivalent however.