Advertisement
HowToRoblox

AirdropSpawner

Jan 5th, 2023
1,648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1. local dss = game:GetService("DataStoreService")
  2. local cashDS = dss:GetDataStore("PLAYERS DATA STORE")
  3.  
  4.  
  5. function saveData(plr)
  6.     if not plr:FindFirstChild("DATA FAILED TO LOAD") then
  7.  
  8.         local cash = plr.leaderstats.Cash.Value
  9.  
  10.         local success, err = nil, nil
  11.         while not success do
  12.             success, err = pcall(function()
  13.                 cashDS:SetAsync(plr.UserId, cash)
  14.             end)
  15.             if err then
  16.                 warn(err)
  17.             end
  18.             task.wait(0.1)
  19.         end
  20.     end
  21. end
  22.  
  23. game.Players.PlayerRemoving:Connect(saveData)
  24. game:BindToClose(function()
  25.     for _, plr in pairs(game.Players:GetPlayers()) do
  26.         saveData(plr)
  27.     end
  28. end)
  29.  
  30. game.Players.PlayerAdded:Connect(function(plr)
  31.  
  32.     local dataFailedWarning = Instance.new("StringValue")
  33.     dataFailedWarning.Name = "DATA FAILED TO LOAD"
  34.     dataFailedWarning.Parent = plr
  35.  
  36.     local success, plrData = nil, nil
  37.     while not success do
  38.         success, plrData = pcall(function()
  39.             return cashDS:GetAsync(plr.UserId)
  40.         end)
  41.     end
  42.     dataFailedWarning:Destroy()
  43.  
  44.     if not plrData then
  45.         plrData = 0
  46.     end
  47.  
  48.  
  49.     local ls = Instance.new("Folder")
  50.     ls.Name = "leaderstats"
  51.  
  52.     local cashVal = Instance.new("IntValue")
  53.     cashVal.Name = "Cash"
  54.     cashVal.Value = plrData
  55.     cashVal.Parent = ls
  56.  
  57.     ls.Parent = plr
  58. end)
  59.  
  60.  
  61. local rnd = Random.new()
  62.  
  63. local minTimePerDrop = 2
  64. local maxTimePerDrop = 5
  65.  
  66. local minReward = 5
  67. local maxReward = 10
  68.  
  69. local minFallVelocity = -8
  70. local maxFallVelocity = -12
  71.  
  72. while true do
  73.    
  74.     task.wait(rnd:NextNumber(minTimePerDrop, maxTimePerDrop))
  75.    
  76.    
  77.     local airdrop = script:WaitForChild("Airdrop"):Clone()
  78.    
  79.     local randomPos = Vector3.new(rnd:NextNumber(-1024, 1024), 200, rnd:NextNumber(-1024, 1024))
  80.     local newCF = CFrame.new(randomPos) * CFrame.Angles(0, rnd:NextNumber(0, 2*math.pi), 0)
  81.     airdrop:PivotTo(newCF)
  82.  
  83.     local atch0 = Instance.new("Attachment")
  84.     atch0.Name = "Attachment0"
  85.     atch0.Parent = airdrop.Crate
  86.    
  87.     local lv = Instance.new("LinearVelocity")
  88.     lv.MaxForce = math.huge
  89.     lv.RelativeTo = Enum.ActuatorRelativeTo.World
  90.     lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
  91.     lv.VectorVelocity = Vector3.new(rnd:NextNumber(-5, 5), rnd:NextNumber(maxFallVelocity, minFallVelocity), rnd:NextNumber(-5, 5))
  92.     lv.Attachment0 = atch0
  93.     lv.Parent = airdrop.Crate
  94.    
  95.     local av = Instance.new("AngularVelocity")
  96.     av.MaxTorque = math.huge
  97.     av.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
  98.     av.AngularVelocity = Vector3.new(0, rnd:NextNumber(-1, 1), 0)
  99.     av.Attachment0 = atch0
  100.     av.Parent = airdrop.Crate
  101.    
  102.    
  103.     airdrop.Crate.Touched:Connect(function(hit)
  104.         local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
  105.        
  106.         if plr and hit.Parent.Humanoid.Health > 0 then
  107.            
  108.             airdrop:Destroy()
  109.            
  110.             if not plr:FindFirstChild("DATA FAILED TO LOAD") then
  111.                 plr.leaderstats.Cash.Value += rnd:NextInteger(minReward, maxReward)
  112.             end
  113.         end
  114.     end)
  115.    
  116.    
  117.     airdrop.Parent = workspace
  118.    
  119.    
  120.     task.spawn(function()
  121.         repeat
  122.             task.wait(1)
  123.         until not airdrop or airdrop.Parent ~= workspace or airdrop.Crate.AssemblyLinearVelocity.Y > minFallVelocity
  124.        
  125.         if airdrop and airdrop.Parent == workspace then
  126.             lv:Destroy()
  127.             av:Destroy()
  128.             atch0:Destroy()
  129.            
  130.             airdrop.Crate.Parachute:Destroy()
  131.             airdrop.Parachute.CanCollide = false
  132.            
  133.             game:GetService("Debris"):AddItem(airdrop.Parachute, 5)
  134.         end
  135.     end)
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement