01 | game.Players.PlayerAdded:Connect( function (plr) |
02 | local a = Instance.new( "Folder" ,plr) |
03 | a.Name = "leaderstats" |
04 | local m = Instance.new( "IntValue" ,a) |
05 | m.Value = 0 |
06 | m.Name = "Cash" |
07 | local x = Instance.new( "IntValue" ,a) |
08 | x.Value = 0 |
09 | x.Name = "Mushrooms" |
10 | 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
1 | local GetSaved = DS:GetAsync(plrkey) |
2 | if GetSaved then |
3 | save 1. Value = GetSaved [ 1 ] |
4 | save 2. Value = GetSaved [ 2 ] |
5 |
6 | else |
7 | local NumberForSaving = { save 1. Value, save 2. Value } |
8 | DS:GetAsync(plrkey, NumberForSaving) |
9 | 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:
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local ds 1 = datastore:GetDataStore( "CashSave" ) |
03 | local ds 2 = datastore:GetDataStore( "MushroomsSave" ) |
04 |
05 | game.Players.PlayerAdded:Connect( function (plr) |
06 | local a = Instance.new( "Folder" ,plr) |
07 | a.Name = "leaderstats" |
08 | local m = Instance.new( "IntValue" ,a) |
09 | m.Value = ds 1 :GetAsync(plr.UserId) or 0 |
10 | ds 1 :SetAsync(plr.UserId, m.Value) |
11 | m.Name = "Cash" |
12 | local x = Instance.new( "IntValue" ,a) |
13 | x.Value = ds 2 :GetAsync(plr.UserId) or 0 |
14 | ds 2 :SetAsync(plr.UserId, x.Value) |
15 | x.Name = "Mushrooms" |
16 | end ) |
Then put another script in StarterPlayer > StarterPlayerScripts:
1 | local datastore = game:GetService( "DataStoreService" ) |
2 | local ds 1 = datastore:GetDataStore( "CashSave" ) |
3 | local ds 2 = datastore:GetDataStore( "MushroomsSave" ) |
4 | local player = script.Parent.Parent |
5 |
6 | while wait() do |
7 | ds 1 :SetAsync(player.UserId, player.leaderstats.Cash.Value) |
8 | ds 2 :SetAsync(player.UserId, player.leaderstats.Mushrooms.Value) |
9 | 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.