Tente usar isto
addEventHandler ( "onPlayerLogin", root,
function ( _, acc )
setTimer ( Carregar_Dis, 50, 1, acc )
end
)
function Carregar_Dis ( conta )
if not isGuestAccount ( conta ) then
if conta then
local source = getAccountPlayer ( conta )
local driveDistance = getAccountData ( conta, "driveDistance" ) or 0
setElementData ( source, "driveDistance", driveDistance )
end
end
end
function Iniciar_Resource ( res )
if res == getThisResource ( ) then
for i, player in ipairs(getElementsByType("player")) do
local acc = getPlayerAccount ( player )
if not isGuestAccount ( acc ) then
Carregar_Dis ( acc )
end
end
end
end
addEventHandler ( "onResourceStart", getRootElement ( ), Iniciar_Resource )
function Salvar_Dis ( conta )
if conta then
local source = getAccountPlayer ( conta )
local driveDistance = getElementData ( source, "driveDistance" ) or 0
setAccountData ( conta, "driveDistance", driveDistance )
end
end
function Desligar_Dis ( res )
if res == getThisResource ( ) then
for i, player in ipairs(getElementsByType("player")) do
local acc = getPlayerAccount ( player )
if not isGuestAccount ( acc ) then
Salvar_Dis ( acc )
end
end
end
end
addEventHandler ( "onResourceStop", getRootElement(), Desligar_Dis )
function Sair_Dis_Servidor ( quitType )
local acc = getPlayerAccount(source)
if not isGuestAccount ( acc ) then
if acc then
Salvar_Dis ( acc )
end
end
end
addEventHandler ( "onPlayerQuit", getRootElement(), Sair_Dis_Servidor )
Não testei