local DataStoreService = game:GetService("DataStoreService") local key = 18 local myDataStore = DataStoreService:GetDataStore("Testing" .. key) local playerCount = 0 game.Players.PlayerAdded:Connect(function(player) playerCount += 1 local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local playerstats = Instance.new("Folder", player) playerstats.Name = "playerstats" local StompedTop = Instance.new("IntValue", playerstats) StompedTop.Name = "StompedTop" local timeplayed = Instance.new("IntValue", playerstats) timeplayed.Name = "timeplayed" local hours = Instance.new("IntValue", playerstats) hours.Name = "hours" local CashTop = Instance.new("IntValue", playerstats) CashTop.Name = "CashTop" local RebirthsTop = Instance.new("IntValue", playerstats) RebirthsTop.Name = "RebirthsTop" local Stomped = Instance.new("IntValue", leaderstats) Stomped.Name = "Stomped" local Cash = Instance.new("IntValue", leaderstats) Cash.Name = "Cash" local Rebirths = Instance.new("IntValue", leaderstats) Rebirths.Name = "Rebirths" local CashRebirthCost = Instance.new("IntValue", player) CashRebirthCost.Name = "CashRebirthCost" local HitBoxSize = Instance.new("NumberValue", playerstats) HitBoxSize.Name = "HitBoxSize" local playerUserId = "Player_"..player.UserId -- Load Data local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(playerUserId) end) if success and data then --retrieving data for i, v in pairs(data) do if data[i] < 0 then data[i] = 0 end end Stomped.Value = data[1] Cash.Value = data[2] Rebirths.Value = data[3] StompedTop.Value = data[4] CashTop.Value = data[5] timeplayed.Value = data[6] HitBoxSize.Value = data[7] RebirthsTop.Value = data[8] hours.Value = data[9] -- Set our data equal to current Cash else warn("errormessage") Stomped.Value = 0 Cash.Value = 0 Rebirths.Value = 0 StompedTop.Value = 0 HitBoxSize.Value = 25 end -- to make rebirth cost work local players = game:WaitForChild("Players") local playergui = player:WaitForChild("PlayerGui") local screengui = playergui:WaitForChild("ScreenGui") local frame = screengui:WaitForChild("Frame") local rebirthCostUpdater = frame:WaitForChild("Price") CashRebirthCost.Value = 200 * Rebirths.Value + 200 rebirthCostUpdater.Text = CashRebirthCost.Value end) local function addTime(player) while true do task.wait(60) player.playerstats.timeplayed.Value += 1 if player.playerstats.timeplayed.Value >= 60 then player.playerstats.hours.Value +=1 end end end game.Players.PlayerAdded:Connect(addTime) local poopy = Instance.new("BindableEvent") game.Players.PlayerRemoving:Connect(function(player) local playerUserId = "Player_"..player.UserId local data = { player.leaderstats.Stomped.Value, player.leaderstats.Cash.Value, player.leaderstats.Rebirths.Value, player.playerstats.StompedTop.Value, player.playerstats.CashTop.Value, player.playerstats.timeplayed.Value, player.playerstats.HitBoxSize.Value, player.playerstats.RebirthsTop.Value, player.playerstats.hours.Value } print(string.len(game:GetService("HttpService"):JSONEncode(data))) local success, errormessage = pcall(function() myDataStore:SetAsync(playerUserId, data) end) playerCount -= 1 poopy:Fire() if success then print("Data successfully saved!") else print("There was an error saving, oh no :C") warn(errormessage) end end) game:BindToClose(function() while playerCount > 0 do poopy.Event:Wait() end end)