Advertisement
HowToRoblox

BombTagServer

Dec 5th, 2022
1,469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.85 KB | None | 0 0
  1. --Data handling
  2. local dss = game:GetService("DataStoreService")
  3. local ds = dss:GetDataStore("DATA STORES")
  4.  
  5.  
  6. function saveData(plr)
  7.  
  8.     if not plr:FindFirstChild("FAILED TO LOAD DATA") then
  9.         local cash = plr.leaderstats.Cash.Value
  10.  
  11.         local success, err = nil, nil
  12.         while not success do
  13.             success, err = pcall(function()
  14.                 return ds:SetAsync(plr.UserId, cash)
  15.             end)
  16.             warn(err)
  17.             task.wait(0.1)
  18.         end
  19.     end
  20. end
  21.  
  22. game.Players.PlayerRemoving:Connect(saveData)
  23. game:BindToClose(function()
  24.     for i, plr in pairs(game.Players:GetPlayers()) do
  25.         saveData(plr)
  26.     end
  27. end)
  28.  
  29.  
  30. game.Players.PlayerAdded:Connect(function(plr)
  31.  
  32.     local ls = Instance.new("Folder")
  33.     ls.Name = "leaderstats"
  34.     ls.Parent = plr
  35.  
  36.     local cashValue = Instance.new("IntValue")
  37.     cashValue.Name = "Cash"
  38.     cashValue.Parent = ls
  39.  
  40.  
  41.     local success, data = pcall(function()
  42.         return ds:GetAsync(plr.UserId)
  43.     end)
  44.  
  45.     if success then
  46.         cashValue.Value = data or 0
  47.  
  48.     else
  49.         local failedValue = Instance.new("StringValue")
  50.         failedValue.Name = "FAILED TO LOAD DATA"
  51.         task.wait(1)
  52.         failedValue.Parent = plr
  53.     end
  54. end)
  55.  
  56.  
  57.  
  58. local rs = game.ReplicatedStorage:WaitForChild("BombTagReplicatedStorage")
  59. local config = require(rs:WaitForChild("CONFIGURATION"))
  60. local maps = rs:WaitForChild("Maps")
  61.  
  62.  
  63. local status = Instance.new("StringValue")
  64. status.Name = "STATUS"
  65. status.Parent = rs
  66.  
  67. local currentTagged = Instance.new("ObjectValue")
  68. currentTagged.Name = "CURRENT TAGGED PLAYER"
  69. currentTagged.Parent = rs
  70.  
  71. local explodeTimer = Instance.new("IntValue")
  72. explodeTimer.Name = "EXPLODE TIMER"
  73. explodeTimer.Parent = rs
  74.  
  75.  
  76. function getPlayers(playerList)
  77.    
  78.     local playerList = playerList or game.Players:GetPlayers()
  79.     local playersInGame = {}
  80.  
  81.     for i, plr in pairs(playerList) do
  82.         local char = plr.Parent == game.Players and plr.Character or plr
  83.         if char and char:FindFirstChild("Humanoid") and char.Humanoid.Health > 0 then
  84.             table.insert(playersInGame, char)
  85.         end
  86.     end
  87.     return playersInGame
  88. end
  89.  
  90.  
  91. while true do
  92.    
  93.     local playersInGame = {}
  94.    
  95.     while #playersInGame < config.MinimumPlayersNeeded do
  96.         playersInGame = getPlayers()
  97.        
  98.         if #playersInGame < config.MinimumPlayersNeeded then
  99.             local neededPlayers = config.MinimumPlayersNeeded - #playersInGame
  100.            
  101.             status.Value = "Waiting for " .. neededPlayers .. " more player" .. (neededPlayers ~= 1 and "s" or "")
  102.  
  103.             task.wait(1)
  104.         end
  105.     end
  106.    
  107.     for i = config.IntermissionTime, 0, -1 do
  108.         status.Value = "Choosing map in " .. i .. " seconds"
  109.         task.wait(1)
  110.     end
  111.    
  112.     local chosenMap = maps:GetChildren()[Random.new():NextInteger(1, #maps:GetChildren())]:Clone()
  113.     chosenMap.Parent = workspace
  114.    
  115.     status.Value = "Now entering " .. chosenMap.Name
  116.    
  117.     task.wait(config.MapWaitTime)
  118.    
  119.    
  120.     playersInGame = getPlayers()
  121.    
  122.     if #playersInGame < config.MinimumPlayersNeeded then
  123.         break
  124.     else
  125.        
  126.         local tagDebounce = false
  127.         for i, char in pairs(playersInGame) do
  128.            
  129.             char.Humanoid.WalkSpeed = config.SurvivorSpeed
  130.             char.HumanoidRootPart.CFrame = chosenMap.SPAWN.CFrame
  131.            
  132.             char.Humanoid.Touched:Connect(function(hit)
  133.                 if not tagDebounce and currentTagged.Value then
  134.                    
  135.                     local hitChar = hit.Parent
  136.                     if game.Players:GetPlayerFromCharacter(hitChar) then
  137.                        
  138.                         if char == currentTagged.Value then
  139.                             tagDebounce = true
  140.                            
  141.                             char.Humanoid.WalkSpeed = config.SurvivorSpeed
  142.                             hitChar.Humanoid.WalkSpeed = config.TaggedSpeed
  143.                            
  144.                             currentTagged.Value = hitChar
  145.                            
  146.                             task.wait(config.TagCooldown)
  147.                             tagDebounce = false
  148.                            
  149.                         elseif hitChar == currentTagged.Value then
  150.                             tagDebounce = true
  151.                            
  152.                             hitChar.Humanoid.WalkSpeed = config.SurvivorSpeed
  153.                             char.Humanoid.WalkSpeed = config.TaggedSpeed
  154.  
  155.                             currentTagged.Value = char
  156.  
  157.                             task.wait(config.TagCooldown)
  158.                             tagDebounce = false
  159.                         end
  160.                     end
  161.                 end
  162.             end)
  163.         end
  164.        
  165.         local iterations = 0
  166.         while true do
  167.             iterations += 1
  168.            
  169.             playersInGame = getPlayers(playersInGame)
  170.            
  171.             if #playersInGame > 1 then
  172.                 local randomChar = playersInGame[Random.new():NextInteger(1, #playersInGame)]
  173.                 randomChar.Humanoid.WalkSpeed = config.TaggedSpeed
  174.                
  175.                 if iterations == 1 then
  176.                     randomChar.HumanoidRootPart.Anchored = true
  177.                    
  178.                     for i = config.PreparationTime, 0, -1 do
  179.                         status.Value = randomChar.Name .. " is tagged. You have " .. i .. "s to run."
  180.                         task.wait(1)
  181.                     end
  182.                     currentTagged.Value = randomChar
  183.                     status.Value = randomChar.Name .. " is tagged"
  184.                     randomChar.HumanoidRootPart.Anchored = false
  185.                    
  186.                 else
  187.                     currentTagged.Value = randomChar
  188.                     status.Value = randomChar.Name .. " is tagged"
  189.                 end
  190.                
  191.                 local explodesIn = config.BombExplodeTimes[#playersInGame]
  192.                 explodeTimer.Value = explodesIn
  193.                
  194.                 local bombTimerStarted = tick()
  195.                 while tick() - bombTimerStarted < explodesIn do
  196.                    
  197.                     game:GetService("RunService").Heartbeat:Wait()
  198.                     explodeTimer.Value = explodesIn - math.round(tick() - bombTimerStarted)
  199.                    
  200.                     if not currentTagged.Value or #getPlayers(playersInGame) < 2 then
  201.                         break
  202.                     end
  203.                 end
  204.                
  205.                 if currentTagged.Value and #getPlayers(playersInGame) >= 2 then
  206.                     local explosion = Instance.new("Explosion")
  207.                     explosion.DestroyJointRadiusPercent = 0
  208.                     explosion.Position = currentTagged.Value.HumanoidRootPart.Position
  209.                     explosion.Parent = workspace
  210.                    
  211.                     currentTagged.Value.Humanoid.Health = 0
  212.                     currentTagged.Value = nil
  213.                 end
  214.             else
  215.                 break
  216.             end
  217.         end
  218.        
  219.         local winner = game.Players:GetPlayerFromCharacter(playersInGame[1])
  220.         if winner then
  221.             winner.leaderstats.Cash.Value += config.SurviveReward
  222.             status.Value = winner.Name .. " wins!"
  223.         end
  224.        
  225.         chosenMap:Destroy()
  226.         for i, plr in pairs(game.Players:GetPlayers()) do
  227.             plr:LoadCharacter()
  228.         end
  229.        
  230.         task.wait(config.RoundEndTime)
  231.     end
  232. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement