· 4 years ago · Apr 06, 2021, 11:42 PM
1local DS = game:GetService("DataStoreService"):GetDataStore("Sim_1") -- This is your game key. If you change it, this will initiate a global stat reset. This basically means that everyones stats will be reset.
2game.Players.PlayerAdded:Connect(function(plr)
3 wait()
4 local plrkey = "id_"..plr.userId
5
6 local savevalue = plr.leaderstats:WaitForChild("Points") -- This will be your first value in your leaderstats script, it's cApItAl sEnSiTiVe by the way.
7 local savevalue2 = plr.leaderstats:WaitForChild("Rebirths") -- This is your secondary value. If you want to add more, copy and paste the same line and cahnge the number to 3
8 -- Extra values will go here. If you have more, it'll be: local savevalue3 = plr.leaderstats:WaitForChild(<Value Name>)
9
10 local GetSaved = DS:GetAsync(plrkey)
11 if GetSaved then
12 savevalue.Value = GetSaved[1]
13 savevalue2.Value = GetSaved[2]
14 -- Any extra values that you want to save go here. If you have a 3rd, it'll be: savevalue3.Value = GetSaved[3]
15 else
16 local NumbersForSaving = {savevalue.Value, savevalue2.Value}
17 DS:GetAsync(plrkey, NumbersForSaving)
18 end
19end)
20
21game.Players.PlayerRemoving:Connect(function(plr)
22 DS:SetASync("id_"..plr.userId, {plr.leaderstats.Points.Value, plr.leaderstats.Rebirths.Value})
23end)
24
25-- Note: The SaveData script isn't going to work for you on Roblox Studio. In order for it to work, you have to go into the actual game.
26-- If the SaveData script doesn't work for you, follow these steps:
27-- 1) Go to https://www.roblox.com/create
28-- 2) Find your game, click the options button on it and go to "Configure Game"
29-- 3) Click the box that says "Enable Roblox to use Studio API Services" to make sure the box is checked
30-- 4) Save your changes
31-- 5) Shutdown all servers in the game
32-- 6) Rejoin the game :D