SHARE
TWEET

Untitled

a guest Aug 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local dataStores = game:GetService("DataStoreService"):GetDataStore("BucksDataStore")
  2. local defaultCash = 100
  3. local playersLeft = 0
  4.  
  5. game.Players.PlayerAdded:Connect(function(Player)
  6.    
  7.     playersLeft = playersLeft + 1
  8.    
  9.     local leaderStats = Instance.new("Folder")
  10.     leaderStats.Name = "leaderstats"
  11.     leaderStats.Parent = Player
  12.    
  13.     local bucks = Instance.new("IntValue")
  14.     bucks.Name = "Bucks"
  15.     bucks.Value = 0
  16.     bucks.Parent = leaderStats
  17.    
  18.     Player.CharacterAdded:Connect(function(character)
  19.         character.Humanoid.Died:Connect(function()
  20.             -- Whenever somebody dies, this event will run
  21.            
  22.             if character.Humaniod and character.Humaniod:FindFirstChild("creater") then
  23.                 game. ReplicatedStorage.Status.Value = tostring(character.Humaniod.creator.Value).."Killed"..player.Name
  24.             end
  25.             if character:FindFirstChild("GameTag") then
  26.                 character.GameTag:Destroy()
  27.             end
  28.            
  29.            
  30.             Player:LoadCharacter()
  31.         end)
  32.     end)
  33.    
  34.     -- Data Stores
  35.    
  36.     local player_data
  37.    
  38.     pcall(function()
  39.         player_data = dataStores:GetAsync(Player.UserId.."-Bucks")
  40.     end)
  41.    
  42.     if player_data ~= nil then
  43.         -- Player has saved data, load it in
  44.         bucks.Value = player_data
  45.     else
  46.         -- New Player
  47.         bucks.Value = defaultCash
  48.        
  49.     end
  50.    
  51. end)
  52.  
  53. local bindableEvent = Instance.new("BindableEvent")
  54.  
  55. game.Players.PlayerRemoving:Connect(function(player)
  56.    
  57.     pcall(function()
  58.         dataStores:SetAsync(player.UserId.."-Bucks",player.leaderstats.Bucks.Value)
  59.         print("Saved")
  60.         playersLeft = playersLeft - 1
  61.         bindableEvent:Fire()
  62.     end)
  63.    
  64. end)
  65.  
  66. game:BindToClose(function()
  67.     -- This will bve triggered upon shutdown
  68.     while playersLeft > 0 do
  69.         bindableEvent.Event:Wait()
  70.     end
  71. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top