Hey, I got the Problem (and cant solve it) that my script is working fine but when I reconnect nothing works until I restart the script. Can someone pls help me? Thank you for the help 
Fun fact: the Marker is getting drawn like everytime
Citizen.CreateThread(function()
while true do
playerCoords = GetEntityCoords(playerPed)
DrawMarker(27, Config.exitMarker, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 124, 0, 206, 100, false, false, 2, true, false, false, false)
if Vdist(Config.exitMarker, playerCoords) < 2 then
showInfobar(Config.exitText)
if IsControlJustReleased(0, 38) then
TriggerServerEvent(âdd_entrysystem:CheckPlayerWhitelistStatusâ)
end
end
Citizen.Wait(0)
end
end)
Is there any error when you reconnect? Have you try putting some debug? If so can you provide use some debug.
And try PlayerPedId() insted of PlayerPed
I ve got playerpedid defined in a local but no errors
Edit: when I come home from work I will put some âprintâ in the code for debug
Here is the debug stuff (I edited the script a bit):

EDIT: the ------STUFF------- thing is not working as well (its ciming with an command) when I restart the script it both works âŚ
That is likely the cause of this behavior: something you do on load is changing the player ped (e.g. calling SetPlayerModel) and youâre not updating the âlocalâ.
Iâve had the same problem with some of my scripts.
Instead of assigning PlayerPedId() to a variable outside of loop, do it inside it.
Not the best or the most optimized way of handling a playerPed but you gotta do what you gotta do.
But if you want to keep your precious optimization as good as you can you can always overwrite the variable with current playerPed on âplayerSpawnedâ event. But I found out its not always the best way and it sometimes didnât work for me.
local playerPed = PlayerPedId()
AddEventHandler("playerSpawned", function()
playerPed = PlayerPedId() --or GetPlayerPed(-1)
end)
CreateThread(function()
--some stuff
while true do
-whole drawMarker thing
end
end)
Can you explain it more ?
What do you mean and what is the event handler for? Thank you for helping
He define the pedid on player spawn, can you try using PlayerPedId() instead of PlayerPed, and printing Vdist(Config.exitMarker, playerCoords) instead of âTest1â, so we can see whatâs happening, and when you are ingame try moving a little bit to see if Vdist is changing
And please try 2.0 instead of 2, its a float, and sometimes it do need the .0 after it
Thank you I will try it out tomorrow
Keep us up to date, even if its working
Just wondering something have you declare youâre playerPed variable outside of a Citizen.CreatheThread(function())? If so its the problem, cause you canât declare a playerped if the ped is not connected
f8 is empty
EDIT: when I restart scripts position is showing up in f8
You may want to try my idea.
Here is a piece of code from my own server for dealing with whether or not youâve spawned or smth.
local ESX = exports.es_extended:getSharedObject()
XYZ.RegisterSpawnFunction = function(cb,loaded)
if loaded then
CreateThread(function()
while not ESX.IsPlayerLoaded() do
Wait(10)
end
cb()
end)
elseif not loaded then
CreateThread(function()
while not XYZ.Spawned and not ESX.IsPlayerLoaded() do
Wait(10)
end
cb()
end)
end
end
XYZ.Spawned is the same thing as firstSpawned in some scripts, and ESX.IsPlayerLoaded() is because if you restart the script, you have firstSpawned set as false, and you canât unload a player magically(unless you restart the whole framework, still its using ESX, standalone down below)
You can try doing something like this.
local playerPed = PlayerPedId()
AddEventHandler('playerSpawned', function() -- triggered with for example /revive for ESX
playerPed = PlayerPedId() -- Override playerPed with current ped after respawn
end)
CreateThread(function()
playerPed = PlayerPedId() -- just because you can :D
while true do
--Whole loop you have there
end
end)
The second version is more elegant and better, standalone! No Framework required, but if you use ESX or QBCore you may want to check if player is loaded before the loop, for ESX it would be
local ESX = exports.es_extended:getSharedObject()
local playerPed = PlayerPedId()
AddEventHandler('playerSpawned', function() -- leave it for the sake of it
playerPed = PlayerPedId()
end)
CreateThread(function()
while not ESX.IsPlayerLoaded()do
Wait(10)
end
playerPed = PlayerPedId() -- override after ped is really loaded
while true do
--Whole loop you have there
end
end)
I left the event since you may loose the track of your current ped either way, it doesnât eat much of optimization and it wonât hurt you. I personally would stick with the second example, its much better and more elegant. Unless you need the player to be specifically loaded before anything.
Anyway, I hope it helps!
Hey thank you verry much for helping me out that much, the thing is that i work with QB Core ^^
Iâve looked at source code of QBCore and found nothing like IsPlayerLoaded, you may be able to modify it a little to change the value to true of some variable.
But for your needs you can stick to the num 2 example. It should work just fine for you.
Lmk if it works or not 
P.S. when I say num 2 I mean the second example, not the last one
I use this trigger at the beginning, can I use it in this case as well?

still does not work⌠tried it your way and tried it my way ⌠wtf is that
I am rewriting everything at the moment and I think i got the problem:
I did that:

but thats the right way:

I ll keep u up if it all works but going asleep now