[Help] Drawmarker only shows up after restarting resource while player is loaded

I’m not sure what is wrong. No marker is drawn.
If the player is in the server, and the resource is restarted the marker draws? But not when the player first joins…
No errors in the logs at all.

Citizen.CreateThread(function()
		Citizen.Trace("Loading Train Markers.")
		while true do		
			Wait(0)
			if Config.ModelsLoaded then
				local coords = GetEntityCoords(Config.localPed)		
				for i=1, #Config.TrainLocations, 1 do
					if(GetDistanceBetweenCoords(coords, Config.TrainLocations[i].x, Config.TrainLocations[i].y, Config.TrainLocations[i].z, true) < Config.DrawDistance) then
						DrawMarker(Config.MarkerType, Config.TrainLocations[i].x, Config.TrainLocations[i].y, Config.TrainLocations[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z-2.0, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 75, 0, 1, 2, 0, 0, 0, 0)
					end
					if(GetDistanceBetweenCoords(coords, Config.TrainLocations[i].x, Config.TrainLocations[i].y, Config.TrainLocations[i].z, true) < Config.MarkerSize.x / 2) then
						if(IsControlPressed(0,58) and(GetGameTimer() - Config.EnterExitDelay) > Config.EnterExitDelayMax) then -- G
							Config.EnterExitDelay = 0
							Wait(60)
							createNewTrain(Config.TrainLocations[i].trainID, Config.TrainLocations[i].trainX, Config.TrainLocations[i].trainY, Config.TrainLocations[i].trainZ)
						end
					end
				end
			end
		end
	end)

I’m stumped. I even put everything from my config.lua into my client.lua (main file) to see if it wasn’t loading the config on time, but it is (It still didn’t work). So I have no idea why it’s occurring…

Here is the config it’s referencing

Config.TrainLocations = {
	{ ['x'] = 247.965,  ['y'] = -1201.17,  ['z'] = 38.92, ['trainID'] = 24, ['trainX'] = 247.9364, ['trainY'] = -1198.597, ['trainZ'] = 37.4482 }, -- Trolley
	{ ['x'] = 670.2056,  ['y'] = -685.7708,  ['z'] = 25.15311, ['trainID'] = 2, ['trainX'] = 670.2056, ['trainY'] = -685.7708, ['trainZ'] = 25.15311 }, -- FTrain
}

Are you actually detecting the player join event

My thought is that this is running before you are actually spawned in, so it is throwing some error. When you restart the resource, you are obviously already spawned in, so no error.

Nope, I join the server, no markers. Everything else loads, even the map blips I have scripted in.

Maybe? But I’m not getting any errors in the log… I tried to hook into the event when the player spawns but that didn’t work either :confused: Am I doing something wrong?

Maybe your code isn’t setting ModelsLoaded in a loop, and when restarting, as by then they will have loaded, it does set the value?

I setup the loop to be started after I ran a command. It still only works after restarting the resource…?

Config.localPed = GetPlayerPed(PlayerId())

Was my problem. Some reason PlayerId() doesn’t exist unless you restart the resource…?

GetPlayerPed(-1) fixed my problem ;-;

3 Likes