Hi there! I have two scripts - one for playerentering and one for playerremoving. For some reason, it doesn't save :/ Any ideas? Thanks
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)
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)

4 comments
Please fix you code so it's all in appropriate Lua code block.
oops - sorry! Didn't notice it had done that!
Does it not save for player removing only?
If you're testing this with just one player, consider using game.OnClose: http://wiki.roblox.com/index.php?title=API:Class/DataModel/OnClose