#need help (DataStore)

4 messages · Page 1 of 1 (latest)

velvet dagger
#

function PlayerLeaving(player)
if sessionData[player.UserId] then
local success = nil
local errorMsg = nil
local attempt = 1

    repeat
        success, errorMsg = pcall(function()
            database:SetAsync(player.UserId, sessionData[player.UserId])
        end)
        
        attempt += 1
        if not success then
            warn(errorMsg)
            task.wait(3)
        end
    until success or attempt == 5
    
    if success then
        print("Data saved for", player.Name)
    else
        warn("Unable to save for", player.Name)
        
    end
end

end
Players.PlayerRemoving:Connect(PlayerLeaving)

function ServerShutdown()
if RunService:IsStudio() then
return
end

print("Server shutting down..")
for i, player in ipairs(Players:GetPlayers()) do
    task.spawn(function()
        PlayerLeaving(player)
    end)
end

end
game:BindToClose(ServerShutdown)

#

i followed a tutorial but it don't work, it says "Data saved for" but only like 1 time and it doesn't even save the data

halcyon wadi
#

You could try using ProfileService

latent crescent