local QBCore = exports['qb-core']:GetCoreObject() RegisterServerEvent("relog:saveCoords", function(coords) local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then return end local data = { x = coords.x, y = coords.y, z = coords.z, w = GetEntityHeading(GetPlayerPed(src)) } MySQL.update('UPDATE players SET last_position = ? WHERE citizenid = ?', { json.encode(data), Player.PlayerData.citizenid }) QBCore.Player.Logout(src) SetPlayerRoutingBucket(src, 0) end) RegisterServerEvent("relog:checkLastPosition", function() local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then return end local result = MySQL.single.await('SELECT last_position FROM players WHERE citizenid = ?', { Player.PlayerData.citizenid }) if result and result.last_position then local pos = json.decode(result.last_position) TriggerClientEvent("relog:teleportPlayer", src, pos) end end)