I'm using a datastore to save my stats like Wood, etc.. You get wood by clicking on trees, but when I test this, I get for example 3 wood, but when I enter the game back I only have 2 wood? I lose random ammounts of my stats randomly, but my datastore seems to work fine, please help!
This is the data-store script.
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("WoodSaveSystem")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("Folder",player)
stats.Name = "Stats"
local Wood = Instance.new("IntValue", stats)
Wood.Name = "Wood"
Wood.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Wood.Value)
Wood.Changed:connect(function()
ds:SetAsync(player.UserId, Wood.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.Stats.Wood.Value)
end)

4 comments
stop using this code, it isn't great, has no pcall to back it up, can cause lots of datastore losses...
I think for now no pcall is fine since pcall doesn't let you see the error.About the question can you add more specific details.
I think the leaderstats is supposed to be a model, based on other scripts.
http://wiki.roblox.com/index.php/Data_store