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

Datastore not working anymore, can someone explain please?

Asked by
xNypify 11
5 years ago

It was working fine yesterday and days before then, I just tested it today and now it doesn't save anything. It also gives off no errors in the output.

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderboardSaveSystem")
local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(player) 
    local key = tostring(player.UserId) 
    local data = ds:GetAsync(key) 
    local leader = Instance.new("Folder") 
    leader.Name = "leaderstats"
    leader.Parent = player 
    local Speed = Instance.new("NumberValue", leader)
    Speed.Name = "Speed"
    local Rebirth = Instance.new("NumberValue", leader)
    Rebirth.Name = "Rebirth"
    local GemVal = Instance.new("NumberValue", player)
    GemVal.Name = "GemVal"
    local Purchase1 = Instance.new("BoolValue", player)
    Purchase1.Name = "RedTrail"
    local success, msg = pcall(function() 
        if data then  
            Speed.Value = data[1]
            Rebirth.Value = data[2]
            GemVal.Value = data[3]
            Purchase1.Value = data[4]
        else 
            Speed.Value = 0 
            Rebirth.Value = 0
            GemVal.Value = 0
            Purchase1.Value = false
        end
    end)
end) 


Players.PlayerRemoving:Connect(function(player)
    local data = {  
        player.leaderstats.Speed.Value,
        player.leaderstats.Rebirth.Value,
        player.GemVal.Value,
        player.Purchase1.Value
    }

    local key = tostring(player.UserId)
    print("player left:", player)
    ds:SetAsync(key, data)
end)

0
Going to mention that it does still provide the previous data that players had before it stopped saving. xNypify 11 — 5y
0
pretty sure it's a problem at roblox. mixgingengerina10 223 — 5y
0
I thought they fixed that earlier this morning? xNypify 11 — 5y
0
If it worked before, then just wait for roblox to make a fix if they haven't done so already RAYAN1565 691 — 5y
View all comments (3 more)
0
Alright, I thought I was the only one w/ this issue after the previous "fix". xNypify 11 — 5y
0
Parent argument to Instance.new is deprecated. User#19524 175 — 5y
0
what/how else am I supposed to be using it? xNypify 11 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Roblox made a function inside the DataModel class called BindToClose(function)

Here's some notes on the Roblox API about this function.

Description: Schedules the given function to be called when the game is about to shut down.

Note: The purpose of this is to give creators a chance to save data using HttpService or Data Store before the game shuts down.

You can find it on Roblox's API page here: https://wiki.roblox.com/index.php?title=API:Class/DataModel/BindToClose

Above this:

Players.PlayerRemoving:Connect(function(player) 

Add this:

game:BindToClose(function()
    wait(3)
    print("Done")
end)

Note: If your Datastore isn't working on Roblox Studio it might just be an issue with their servers and should only be a problem in your Roblox Studio but will work in online mode on their real servers so test that too.

0
It happen in both test and real servers, and I tried adding the function in and it hasn't fixed my current issue :( xNypify 11 — 5y
0
Does your debug console print out on line 45? Looks like you need more debugging for yourself then. My Datastore works but mines also different. Maybe rewrite your script and use pcalls for getasync and setasync for return values Impacthills 223 — 5y
0
It started to work now, I'm just gonna assume that it was on roblox's part? xNypify 11 — 5y
Ad

Answer this question