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

Why is the DataStore not working?

Asked by
mine248 40
8 years ago

So I made a DataStore script in and it did not work. Any fixes?

Faulty script 1:

local DataStore = game:GetService("DataStoreService"):GetDataStore("PeasStore")


game.Players.PlayerAdded:connect(function(player)

    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

    local cash = Instance.new("IntValue", stats)
    cash.Name = "Money"
    cash.Value = cash.Value + 100

    local key = "player-"..player.userId

    local savedValues = DataStore:GetAsync(key)

    if savedValues then
        --Save format: {cash, coins}
        cash.Value = savedValues
    else
        local valuesToSave = {cash.Value}
        DataStore:SetAsync(key, valuesToSave)
    end

end)

Faulty code 2:

local DataStore = game:GetService("DataStoreService"):GetDataStore("PeasStore")

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

    local key = "player-"..player.userId

    --Save key: {cash}
    local valuesToSave = {player.leaderstats.Money.Value}
    DataStore:SetAsync(key, valuesToSave)

end)

1 answer

Log in to vote
0
Answered by 8 years ago

You must use Start Server instead of Play Solo, otherwise Studio will not be able to use DataStores. Also, you must Enable API Access in Studio.

0
I did start a server, and also enabled the API access in studio, but it doesn't work. mine248 40 — 8y
Ad

Answer this question