Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Thanks for using this script
- This script is made by Joriangames/Problox Studio Scripts
- Want to know how to use this and script explanation?
- Watch my tutorial: https://youtu.be/ftCgYgQ-qpM
- Don't forget to turn on API services and Publish the game!
- ]]
- local DSS = game:GetService("DataStoreService")
- local statsDS = DSS:GetDataStore("statsDS")
- game.Players.PlayerAdded:Connect(function(plr)
- local lead = Instance.new("Folder")
- lead.Name = "leaderstats"
- lead.Parent = plr
- local cash = Instance.new("IntValue")
- cash.Name = "Cash"
- cash.Parent = lead
- cash.Value = 0
- local diam = Instance.new("IntValue")
- diam.Name = "Diamonds"
- diam.Parent = lead
- cash.Value = 0
- local Reb = Instance.new("IntValue")
- Reb.Name = "Rebirths"
- Reb.Parent = lead
- cash.Value = 0
- local data
- local succ, err = pcall(function()
- data = statsDS:GetAsync(plr.UserId.."-stats")
- end)
- if succ then
- print("success")
- if data then --if there was some data then
- print("Got the data from the player datastore")
- cash.Value = data[1]
- diam.Value = data[2]
- Reb.Value = data[3]
- end
- else
- print("There was an error while checking: "..plr.Name)
- warn(err)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(plr)
- print("Player is leaving the game!")
- local cash = plr.leaderstats.Cash.Value
- local diam = plr.leaderstats.Diamonds.Value
- local reb = plr.leaderstats.Rebirths.Value
- print("Got all the values")
- local data = {cash, diam, reb}
- local succ, err = pcall(function()
- statsDS:SetAsync(plr.UserId.."-stats", data)
- end)
- if succ then
- print("Succesfully saved the data!")
- else
- print("There was an error while saving player leaderstats!")
- warn(err)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement