Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

why my data store have a chance to reset data?

Asked by 4 years ago

hi for the past few months i've been using this script for stats data store. but sometimes your data will be resetted. is there a way i could fix it?

local DataStore = game:GetService("DataStoreService")

local myDataStore = DataStore:GetDataStore("EpicStorage")

    game.Players.PlayerAdded:Connect(function(player)
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player

        local minutes = Instance.new("IntValue")
        minutes.Name = "Minutes"
        minutes.Parent = leaderstats

        local data
        local success, errormessage = pcall(function()
            data = myDataStore:GetAsync(player.UserId.."-minutes")
    end)

    if success then
        minutes.Value = data
    else
        print("Error when saving data")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-minutes",player.leaderstats.Minutes.Value)
    end)

    if success then
        print("Data successfully saved!")
    else
        print("Data save is unsuccessful!")
        warn(errormessage)
    end
end)
0
I'm pretty sure there is no way to prevent it, since it's a roblox problem. You can make another datastore to have as an backup, but there is still a chance BOTH of these will fail and your data gets resetted. User#32819 0 — 4y
0
I'm pretty sure you can kick the player when something goes wrong. Dovydas1118 1495 — 4y
0
Kicking won't do anything, since when the player joins the data will be resetted, and when you kick him it will save the data AFTER it has been resetted. User#32819 0 — 4y
0
auto saves? kkfilms_1 68 — 4y

Answer this question