Drawmarker not loading on server startup, it requires me to restart the resource to see it

Hi! Im having a issue where I have written some code for a clockin system but whenever I go to see it when the server restarts it does not work unless i restart the resource.

Client.lua code:

local markerPos = vector3(440.12, -975.72, 30.69)
local HasAlreadyGotMessage = false

Citizen.CreateThread(function()
local ped = GetPlayerPed(-1)
while true do
Citizen.Wait(0)
local playerCoords = GetEntityCoords(ped)
local distance = #(playerCoords - markerPos)
local isInMarker = false
if distance < 300.0 then
DrawMarker(25, markerPos.x, markerPos.y, markerPos.z - 1, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 2.0, 2.0, 2.0, 255, 128, 0, 50, false, true, 2, nil, nil, false)
if distance < 2.0 then
isInMarker = true
else
HasAlreadyGotMessage = false
end
else
Citizen.Wait(2000)
end

    if isInMarker and not HasAlreadyGotMessage then
        TriggerEvent('chatMessage', 'Press E to Interact with clock in system')
        HasAlreadyGotMessage = true
    end
end

end)

FxManifest code:

fx_version “bodacious”

games {“gta5”}

client_script “client.lua”

Can anyone help! Thanks

any1 know?

Move local ped = GetPlayerPed(-1) into the loop.

Also, use PlayerPedId() instead of GetPlayerPed(-1) - it’s faster.

local markerPos = vector3(440.12, -975.72, 30.69)
local HasAlreadyGotMessage = false

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

        local ped = PlayerPedId()
        local playerCoords = GetEntityCoords(ped)
        local distance = #(playerCoords - markerPos)
        local isInMarker = false

        if distance < 300.0 then
            DrawMarker(25, markerPos.x, markerPos.y, markerPos.z - 1.0, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 2.0, 2.0, 2.0, 255, 128, 0, 50, false, true, 2, nil, nil, false)

            if distance < 2.0 then
                isInMarker = true
            else
                HasAlreadyGotMessage = false
            end
        else
            Wait(2000)
        end

        if isInMarker and not HasAlreadyGotMessage then
            TriggerEvent('chatMessage', 'Press E to Interact with clock in system')
            HasAlreadyGotMessage = true
        end
    end
end)