Facebook
From supper, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 159
  1. local DataStoreService = game:GetService("DataStoreService")
  2. local key = 18
  3. local myDataStore = DataStoreService:GetDataStore("Testing" .. key)
  4. local playerCount = 0
  5.  
  6. game.Players.PlayerAdded:Connect(function(player)
  7.  playerCount += 1
  8.  
  9.  local leaderstats = Instance.new("Folder", player)
  10.  leaderstats.Name = "leaderstats"
  11.  
  12.  local playerstats = Instance.new("Folder", player)
  13.  playerstats.Name = "playerstats"
  14.  
  15.  local StompedTop = Instance.new("IntValue", playerstats)
  16.  StompedTop.Name = "StompedTop"
  17.  
  18.  local timeplayed = Instance.new("IntValue", playerstats)
  19.  timeplayed.Name = "timeplayed"
  20.  
  21.  local hours = Instance.new("IntValue", playerstats)
  22.  hours.Name = "hours"
  23.  
  24.  local CashTop = Instance.new("IntValue", playerstats)
  25.  CashTop.Name = "CashTop"
  26.  
  27.  local RebirthsTop = Instance.new("IntValue", playerstats)
  28.  RebirthsTop.Name = "RebirthsTop"
  29.  
  30.  local Stomped = Instance.new("IntValue", leaderstats)
  31.  Stomped.Name = "Stomped"
  32.  
  33.  local Cash = Instance.new("IntValue", leaderstats)
  34.  Cash.Name = "Cash"
  35.  
  36.  local Rebirths = Instance.new("IntValue", leaderstats)
  37.  Rebirths.Name = "Rebirths"
  38.  
  39.  local CashRebirthCost = Instance.new("IntValue", player)
  40.  CashRebirthCost.Name = "CashRebirthCost"
  41.  
  42.  local HitBoxSize = Instance.new("NumberValue", playerstats)
  43.  HitBoxSize.Name = "HitBoxSize"
  44.  
  45.  
  46.  local playerUserId = "Player_"..player.UserId
  47.  
  48.  -- Load Data
  49.  
  50.  local data
  51.  local success, errormessage = pcall(function()
  52.   data = myDataStore:GetAsync(playerUserId)
  53.  end)
  54.  
  55.  if success and data then --retrieving data
  56.   for i, v in pairs(data) do
  57.    if data[i] < 0 then
  58.     data[i] = 0
  59.    end
  60.   end
  61.   Stomped.Value = data[1]
  62.   Cash.Value = data[2]
  63.   Rebirths.Value = data[3]
  64.   StompedTop.Value = data[4]
  65.   CashTop.Value = data[5]
  66.   timeplayed.Value = data[6]
  67.   HitBoxSize.Value = data[7]
  68.   RebirthsTop.Value = data[8]
  69.   hours.Value = data[9]
  70.   -- Set our data equal to current Cash
  71.  else
  72.   warn("errormessage")
  73.   Stomped.Value = 0
  74.   Cash.Value = 0
  75.   Rebirths.Value = 0
  76.   StompedTop.Value = 0
  77.   HitBoxSize.Value = 25
  78.  end
  79.  
  80.  -- to make rebirth cost work
  81.  local players = game:WaitForChild("Players")
  82.  local playergui = player:WaitForChild("PlayerGui")
  83.  local screengui = playergui:WaitForChild("ScreenGui")
  84.  local frame = screengui:WaitForChild("Frame")
  85.  local rebirthCostUpdater = frame:WaitForChild("Price")
  86.  
  87.  CashRebirthCost.Value = 200 * Rebirths.Value + 200
  88.  rebirthCostUpdater.Text = CashRebirthCost.Value
  89.  
  90. end)
  91.  
  92. local function addTime(player)
  93.  
  94.  while true do
  95.   task.wait(60)
  96.   player.playerstats.timeplayed.Value += 1
  97.   if player.playerstats.timeplayed.Value >= 60 then
  98.    player.playerstats.hours.Value +=1
  99.   end
  100.  end
  101. end
  102.  
  103. game.Players.PlayerAdded:Connect(addTime)
  104.  
  105.  
  106. local poopy = Instance.new("BindableEvent")
  107.  
  108. game.Players.PlayerRemoving:Connect(function(player)
  109.  
  110.  
  111.  local playerUserId = "Player_"..player.UserId
  112.  
  113.  local data = {
  114.   player.leaderstats.Stomped.Value,
  115.   player.leaderstats.Cash.Value,
  116.   player.leaderstats.Rebirths.Value,
  117.   player.playerstats.StompedTop.Value,
  118.   player.playerstats.CashTop.Value,
  119.   player.playerstats.timeplayed.Value,
  120.   player.playerstats.HitBoxSize.Value,
  121.   player.playerstats.RebirthsTop.Value,
  122.   player.playerstats.hours.Value
  123.  }
  124.  
  125.  print(string.len(game:GetService("HttpService"):JSONEncode(data)))
  126.  
  127.  local success, errormessage = pcall(function()
  128.   myDataStore:SetAsync(playerUserId, data)
  129.  end)
  130.  
  131.  playerCount -= 1
  132.  poopy:Fire()
  133.  
  134.  
  135.  if success then
  136.   print("Data successfully saved!")
  137.  else
  138.   print("There was an error saving, oh no :C")
  139.   warn(errormessage)
  140.  end
  141. end)
  142.  
  143.  
  144. game:BindToClose(function()
  145.  while playerCount > 0 do
  146.   poopy.Event:Wait()
  147.  end
  148. end)