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

[SOLVED] Why is my in-game currency Datastore not working?

Asked by 1 year ago
Edited 1 year ago

I have been working on a game that uses in-game currency. I just made a datastore for the game to save the player's currency and work, but when I test it out (In-Studio and on Regular ROBLOX) it doesn't work. And yes, I do have Enable Studio Access to API Services turned on.

Here is my script:

local ds = game:GetService("DataStoreService"):GetDataStore("CoinsSave")

game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local key = "user_"..plr.UserId

    local savevalue = plr.leaderstats.Coins
    local savevalue2 = plr.leaderstats.Level


    local getSaved = ds:GetAsync(key)
    if getSaved then
        savevalue.Value = getSaved[1]
        savevalue2.Value = getSaved[2]
    else
        local NumbersForSaving = {savevalue.Value, savevalue2.Value}

        ds:GetAsync(key, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    ds:SetAsync("id_"..player.UserId, {player.leaderstats.Coins.Value, player.leaderstats.Level.Value})
end)

Any Help?

0
whats the error ur getting? ZeroToH3ro 82 — 1y
0
I don't get any errors. It just does not save. JackyW9cky 27 — 1y
0
It may be because when you set async you do "id_" player Userid, instead of "user_" player Userid, like how you have when the player joins Phase_Venom 55 — 1y
0
Okay thanks. I'll try to replace the "id" to "user". JackyW9cky 27 — 1y
0
I just replaced the "id" to "user" and it worked! Thank you so much! I have been trying to find out how to fix this problem for a very long time. JackyW9cky 27 — 1y

Answer this question