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

the DataStore I added isn't saving my data. Can you tell me where have I gone wrong?

Asked by 3 years ago

Here are my scripts. If you find any errors can you correct them in the answers? Thanks leaderstats script- game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local cash = Instance.new("IntValue")
cash.Name ="Cash"
cash.Value = 0
cash.Parent = leaderstats

end) DataStore script- local ds = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.Cash

local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
    save1.Value = GetSaved[1]
else
    local NumberForSaving = {save1.Value}
    ds:GetAsync(plrkey,NumberForSaving)
end

end)

game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId,{plr.leaderstats.Cash.Value}) end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Try this script and let me know does it work!

local players = game:GetService("Players")
local ds=game:GetService("CashSave")


players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player

    local currency1 = Instance.new("IntValue")
    currency1.Name = "Cash"
    currency1.Parent = player.leaderstats
    currency1.Value = ds:GetAsync(player.UserId) or 0
    ds:SetAsync(player.UserId, currency1.Value)

    currency1.Changed:connect(function()
        ds:SetAsync(player.UserId, currency1.Value)
    end)

end)
0
No it doesn't work crundeeisreeaall 0 — 3y
0
What error are you experiencing and is this placed in workspace or ServerScriptService? SonGohan6 85 — 3y
Ad

Answer this question