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

0

Please fix you code so it's all in appropriate Lua code block.

0

oops - sorry! Didn't notice it had done that!

0

Does it not save for player removing only?

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