game.Players.PlayerAdded:Connect(function(plr) local a = Instance.new("Folder",plr) a.Name = "leaderstats" local m = Instance.new("IntValue",a) m.Value = 0 m.Name = "Cash" local x = Instance.new("IntValue",a) x.Value = 0 x.Name = "Mushrooms" end)
local DS = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait(5) local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.Name local save2 = plr.leaderstats.Name
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.Name.Value, plr.leaderstats.Name.Value}) end)
Use this as the script for the leaderstats otherwise known as the script that was in your question:
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("CashSave") local ds2 = datastore:GetDataStore("MushroomsSave") game.Players.PlayerAdded:Connect(function(plr) local a = Instance.new("Folder",plr) a.Name = "leaderstats" local m = Instance.new("IntValue",a) m.Value = ds1:GetAsync(plr.UserId) or 0 ds1:SetAsync(plr.UserId, m.Value) m.Name = "Cash" local x = Instance.new("IntValue",a) x.Value = ds2:GetAsync(plr.UserId) or 0 ds2:SetAsync(plr.UserId, x.Value) x.Name = "Mushrooms" end)
Then put another script in StarterPlayer > StarterPlayerScripts:
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("CashSave") local ds2 = datastore:GetDataStore("MushroomsSave") local player = script.Parent.Parent while wait() do ds1:SetAsync(player.UserId, player.leaderstats.Cash.Value) ds2:SetAsync(player.UserId, player.leaderstats.Mushrooms.Value) end
After you make these scripts, go into the Game Settings. Here is a picture: https://www.linkpicture.com/view.php?img=LPic60c7adb803e1a33241333
From there go to security and enable studio to access API Services.