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

Datastore not saving?

Asked by 9 years ago

Hi there! I have two scripts - one for playerentering and one for playerremoving. For some reason, it doesn't save :/ Any ideas? Thanks

1.

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

game.Players.PlayerAdded:connect(function(player)
    local knife = Instance.new("BoolValue", player)
    knife.Name = "OwnKnife"

    local cloak = Instance.new("BoolValue", player)
    cloak.Name = "OwnCloak"



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

    local savedvalues = DataStore:GetAsync(key)

    if savedvalues then
        knife.OwnKnife.Value = savedvalues[1]
        cloak.Value = savedvalues[2]
    else
        local ValueToSave = {knife.Value, cloak.Value}
        DataStore:SetAsync(key, ValueToSave)
    end
end)

2.

local datastore = game:GetService("DataStoreService"):GetDataStore("ProductsInShop")
game.Players.PlayerRemoving:connect(function(player)
        local key = "player-"..player.UserId

        local valuestosave = {player.OwnKnife.Value, player.OwnCloak.Value}
        datastore:SetAsync(key, valuestosave)

end)
0
Please fix you code so it's all in appropriate Lua code block. Goulstem 8144 — 9y
0
oops - sorry! Didn't notice it had done that! jjwood1600 215 — 9y
0
Does it not save for player removing only? EzraNehemiah_TF2 3552 — 9y
0
If you're testing this with just one player, consider using game.OnClose: http://wiki.roblox.com/index.php?title=API:Class/DataModel/OnClose chess123mate 5873 — 9y

Answer this question