local DSService = game:GetService("DataStoreService"):GetDataStore("Currency")
local Saving = 0
wait()
game:BindToClose(function()
    repeat wait() until Saving <= 0
end)

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

    local Credits = Instance.new("IntValue")
    Credits.Name = "Credits"
    Credits.Parent = leader

    local Diamonds = Instance.new("IntValue")
    Diamonds.Name = "Diamonds"
    Diamonds.Parent = leader

    local savedData = DSService:GetAsync(plr.UserId.."-Currency")

    if savedData then
        Credits.Value = savedData[1]
        Diamonds.Value = savedData[2]
    else
        local values = {Credits.Value, Diamonds.Value}
        DSService:SetAsync(plr.UserId.."-Currency",values)
    end
end)

game:GetService("Players").PlayerRemoving:Connect(function(plr)
    Saving = Saving + 1
    local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value}
    DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave)
    Saving = Saving - 1
end)


5 comments

0

Can you be more precise? how not working on the live game?

0

Send error. From Output

0

Give me the error message.

0

You just posted this a few questions ago. Please refrain from spamming questions.

0

sorry