[Help] Draw marker only appears after restarting the resource, when it has already been loaded before when starting the server

Hello, I don’t know if there is something wrong in the lines of code, the resource works perfectly, but when you exit the server and log back in, the markers don’t appear, and I have to press f8 and do an ensure Markers, someone could help me ?

local markerPos1 = vector3(446.49, -1025.26, 28.64)

Citizen.CreateThread(function()

    local ped = GetPlayerPed(-1)

    while true do

        Citizen.Wait(1)

        local playerCoords = GetEntityCoords(ped)

        local distance = #(playerCoords - markerPos1)

        if distance < 10.0 then

            DrawMarker(36, markerPos1.x, markerPos1.y, markerPos1.z + 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 220, 220, 220, 15, false, true, 2, nil, nil, false)

        else

            Citizen.Wait(0)

        end

    end

end)

local markerPos2 = vector3(471.13, -1024.05, 28.17)

Citizen.CreateThread(function()

    local ped = GetPlayerPed(-1)

    while true do

        Citizen.Wait(0)

        local playerCoords = GetEntityCoords(ped)

        local distance = #(playerCoords - markerPos2)

        if distance < 10.0 then

            DrawMarker(36, markerPos2.x, markerPos2.y, markerPos2.z + 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 220, 220, 220, 15, false, true, 2, nil, nil, false)

        else

            Citizen.Wait(0)

        end

    end

end)

Instead of

local ped = GetPlayerPed(-1)

Put this:

local ped = PlayerPedId()

Also, put that code inside the while true do loop. The ped changes when a player dies etc and therefore the coords wouldn’t be possible to get since ped isn’t updated constantly. The reason you have to restart before it works is because it is trying to get the ped before they’ve loaded in properly. When they load in properly, it gives them a new ped ID but the ped variable is still stuck on the old ped id.

1 Like