datastore = game:GetService("DataStoreService"):GetDataStore("FarmStatsCJ")
local function set(key,value)
datastore:SetAsync(key,value)
end
local function get(key)
datastore:GetAsync(key)
end
game.Players.PlayerRemoving:connect(function(player)
wait(1)
local l = player.leaderstats
set('leaderstatsFarmCJ1'..player.userId,l.Money)
set('leaderstatsFarmCJ2'..player.userId,l.level)
set('leaderstatsFarmCJ3'..player.userId,l.Harvests)
set('valsFarmCJ1'..player.userId,player.storage.ex.Value)
set('valsFarmCJ2'..player.userId,player.storage.exm.Value)
set('valsFarmCJ3'..player.userId,player.storage.waittime.Value)
set('valsFarmCJ4'..player.userId,player.storage.code.Value)
set('inventoryFarmCJ1'..player.userId,player.inventory.Carrots.Value)
set('inventoryFarmCJ2'..player.userId,player.inventory.Wheat.Value)
set('inventoryFarmCJ3'..player.userId,player.inventory.Corn.Value)
end)
game.Players.PlayerAdded:connect(function(play)
wait(2)
local l = play.leaderstats
local i = play.inventory
local s = play.storage
if l.Money then
l.Money.Value = get('leaderstatsFarmCJ1'..play.userId)
l.level.Value = get('leaderstatsFarmCJ2'..play.userId)
l.Harvests.Value = get('leaderstatsFarmCJ3'..play.userId)
s.ex.Value = get('valsFarmCJ1'..play.userId)
s.exm.Value = get('valsFarmCJ2'..play.userId)
s.waittime.Value = get('valsFarmCJ3'..play.userId)
i.Carrots.Value = get('inventoryFarmCJ1'..play.userId)
i.Wheat.Value = get('inventoryFarmCJ2'..play.userId)
i.Corn.Value = get('inventoryFarmCJ3'..play.userId)
end
end)
The datastore doesn't work, and since I've never used datastore before, I don't know what i did wrong.

1 comment
thank you. the consept of what this is helped me