Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game:GetService("Players")
- local DataStoreService = game:GetService("DataStoreService")
- local DataStore = DataStoreService:GetDataStore("-xBuckDatax-")
- local RunService = game:GetService('RunService')
- local plrFolder = game.Workspace.PlayerFolder
- local key
- local plr
- local plrName
- local plrCount = 0
- -- Making the saving inside a function it shortened your code by a bit.
- local function Save(player)
- if plrCount == 0 then
- print('BindToClose')
- game:BindToClose(Save)
- return
- end
- print(player)
- key = game.Workspace.PlayerFolder:WaitForChild(player.Name).Value
- plr = game.Workspace:WaitForChild(player.Name)
- local save = {
- ["SeerBux"] = player.leaderstats["§ SeerBux"].Value,
- ["SpdWaitTime"] = player.WaitTime.WaitTimeSpd.Value,
- ["StrWaitTime"] = player.WaitTime.WaitTimeStr.Value,
- ["walkSpeed"] = plr.Humaoid.WalkSspeed,
- ["customize"] = player.Customize.Value,
- ["Exp"] = player.leaderstats["ExperiencePts"].Value,
- ["level"] = player.leaderstats["Level"].Value,
- ["SpdCheck"] = player.SpdCheck.Value,
- ['energy'] = player.EnergyCount.Value,
- ['enbool'] = player.EnergyBool.Value
- }
- --saves their key and money to the data store
- local success, err = pcall(function()
- DataStore:SetAsync(key, save)
- end)
- if success then
- print('Success')
- end
- if not success then
- warn("Failed to over-write data"..tostring(err))
- print("Failed to over-write data"..tostring(err))
- return
- end
- print('Successful Save')
- end
- -- This function loads the player's data
- local function Load(player)
- -- saves the player Id as key
- wait(1)
- local key = player.UserId
- local plr = workspace:WaitForChild(player.Name)
- local moneyAlready
- local success, err = pcall(function()
- moneyAlready = DataStore:GetAsync(key)
- end)
- if not success then
- warn("Failed to read data"..tostring(err))
- print("Failed to read data"..tostring(err))
- return
- end
- if moneyAlready then
- player.leaderstats['§ SeerBux'].Value = moneyAlready.SeerBux
- player.WaitTime.WaitTimeSpd.Value = moneyAlready.SpdWaitTime
- player.WaitTime.WaitTimeStr.Value = moneyAlready.StrWaitTime
- plr:WaitForChild('Humanoid').WalkSpeed = moneyAlready.walkSpeed
- player.Customize.Value = moneyAlready.customize
- player.leaderstats.ExperiencePts.Value = moneyAlready.ExperiencePts
- player.leaderstats.Level.Value = moneyAlready.Level
- player.SpdCheck.Value = moneyAlready.SpdCheck
- player.EnergyCount.Value = moneyAlready.energy
- player.EnergyBool.Value = moneyAlready.enbool
- else
- Save(player)
- end
- end
- game.Players.PlayerRemoving:Connect(function()
- plrCount = plrCount - 1
- end)
- game.Players.PlayerAdded:Connect(function()
- plrCount = plrCount + 1
- end)
- game.Players.PlayerAdded:Connect(Load)
- game.Players.PlayerRemoving:Connect(Save)
Advertisement
Add Comment
Please, Sign In to add comment