So i'm making a simulator game on roblox, and you gather fun and sell it to get money or collect coins to get money, but I dont know how to Data Store. My script for Money and Fun is in leaderstats, My script which is in ServerScriptService is here:
codeblock local DS = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userid
local save1 = plr.leaderstats.Fun
local save2 = plr.leaderstats.Money
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberForSaving = {save1.Value, save2.Value}
DS:GetAsync(plrkey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync("id_"..plr.userid, {plr.leaderstats.Fun.Value, plr.leaderstats.Money.Value})
end)
I've tried it multiple times and it does nothing.

1 comment
please add everything in a codeblock. Makes it more organized :)