Advertisement
HowToRoblox

JuggernautServer

Dec 12th, 2022
1,240
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. --Main game
  58. local rs = game.ReplicatedStorage:WaitForChild("JuggernautReplicatedStorage")
  59. local config = require(rs:WaitForChild("Settings"))
  60. local weapons = rs:WaitForChild("Weapons")
  61. local maps = rs:WaitForChild("Maps")
  62.  
  63. local status = Instance.new("StringValue")
  64. status.Name = "STATUS"
  65. status.Parent = rs
  66.  
  67. local rand = Random.new()
  68.  
  69.  
  70. while true do
  71.    
  72.     while true do
  73.         local numPlrs = 0
  74.        
  75.         for _, plr in pairs(game.Players:GetPlayers()) do
  76.             local char = plr.Character
  77.             if char and char.Humanoid.Health > 0 then
  78.                 numPlrs += 1
  79.             end
  80.         end
  81.        
  82.         if numPlrs < config.PlayersRequiredToStart then
  83.             local numPlayersNeeded = config.PlayersRequiredToStart - numPlrs
  84.             status.Value = "Waiting for " .. numPlayersNeeded .. " more player" .. (numPlayersNeeded == 1 and "" or "s")
  85.         else
  86.             break
  87.         end
  88.         task.wait(0.2)
  89.     end
  90.    
  91.    
  92.     for i = config.IntermissionTime, 0, -1 do
  93.         status.Value = "Selecting map in " .. i .. " second" .. (i == 1 and "" or "s")
  94.         task.wait(1)
  95.     end
  96.    
  97.    
  98.     local chosenMap = maps:GetChildren()[rand:NextInteger(1, #maps:GetChildren())]:Clone()
  99.     chosenMap.Parent = workspace
  100.    
  101.     for i = config.MapWaitTime, 0, -1 do
  102.         status.Value = "Entering " .. chosenMap.Name .. " in " .. i .. " second" .. (i == 1 and "" or "s")
  103.         task.wait(1)
  104.     end
  105.    
  106.    
  107.     local playersInGame = {}
  108.  
  109.     for _, plr in pairs(game.Players:GetPlayers()) do
  110.         local char = plr.Character
  111.         if char and char.Humanoid.Health > 0 then
  112.             table.insert(playersInGame, plr)
  113.         end
  114.     end
  115.    
  116.     if #playersInGame < config.PlayersRequiredToStart then
  117.         break
  118.        
  119.     else
  120.         local mapSpawns = chosenMap.Spawns:GetChildren()
  121.         for i, mapSpawn in pairs(mapSpawns) do
  122.             if i <= #playersInGame then
  123.                 playersInGame[i].Character.HumanoidRootPart.CFrame = mapSpawn.CFrame
  124.             end
  125.         end
  126.        
  127.        
  128.         local juggernaut = playersInGame[rand:NextInteger(1, #playersInGame)]
  129.         table.remove(playersInGame, table.find(playersInGame, juggernaut))
  130.         local juggernautCharacter = juggernaut.Character
  131.        
  132.         for property, value in pairs(config.JuggernautHumanoidProperties) do
  133.             juggernautCharacter.Humanoid[property] = value
  134.         end
  135.         juggernautCharacter.Humanoid.Health = juggernautCharacter.Humanoid.MaxHealth
  136.        
  137.         for _, tool in pairs(weapons.JUGGERNAUT:GetChildren()) do
  138.             tool:Clone().Parent = juggernaut.Backpack
  139.         end
  140.        
  141.         local highlight = Instance.new("Highlight")
  142.         highlight.OutlineColor = Color3.fromRGB(123, 46, 255)
  143.         highlight.FillTransparency = 1
  144.         highlight.OutlineTransparency = 0
  145.         highlight.Parent = juggernautCharacter
  146.        
  147.        
  148.         local juggernautHealth = Instance.new("IntValue")
  149.         juggernautHealth.Name = "JUGGERNAUT HEALTH"
  150.         juggernautHealth.Value = juggernautCharacter.Humanoid.Health
  151.         juggernautHealth.Parent = rs
  152.        
  153.         juggernautCharacter.Humanoid.HealthChanged:Connect(function()
  154.             if not juggernautCharacter or not juggernautCharacter:FindFirstChild("Humanoid") or juggernautCharacter.Humanoid.Health <= 0 then
  155.                 juggernautHealth.Value = 0
  156.                 juggernautCharacter = nil
  157.             else
  158.                 juggernautHealth.Value = juggernautCharacter.Humanoid.Health
  159.             end
  160.         end)
  161.        
  162.        
  163.         for _, plr in pairs(playersInGame) do
  164.             local char = plr.Character
  165.            
  166.             if plr ~= juggernaut then
  167.                 for property, value in pairs(config.SurvivorHumanoidProperties) do
  168.                     char.Humanoid[property] = value
  169.                 end
  170.                 char.Humanoid.Health = char.Humanoid.MaxHealth
  171.                
  172.                 for _, tool in pairs(weapons.SURVIVORS:GetChildren()) do
  173.                     tool:Clone().Parent = plr.Backpack
  174.                 end
  175.                
  176.                 char.Humanoid.Died:Connect(function()
  177.                     table.remove(playersInGame, table.find(playersInGame, plr))
  178.                 end)
  179.             end
  180.         end
  181.        
  182.        
  183.         local roundStarted = tick()
  184.         local winner = "SURVIVORS"
  185.        
  186.         while tick() - roundStarted < config.RoundDuration do
  187.            
  188.             local roundCurrentLength = tick() - roundStarted
  189.             local roundEndsIn = math.round(config.RoundDuration - roundCurrentLength)
  190.            
  191.             status.Value = "Round ends in " .. roundEndsIn .. " second" .. (roundEndsIn == 1 and "" or "s")
  192.            
  193.            
  194.             if #playersInGame == 0 then
  195.                 winner = "JUGGERNAUT"
  196.                 break
  197.                
  198.             elseif not juggernautCharacter then
  199.                 break
  200.             end
  201.            
  202.            
  203.             game:GetService("RunService").Heartbeat:Wait()
  204.         end
  205.        
  206.        
  207.         if winner == "SURVIVORS" then
  208.             status.Value = "The survivors won!"
  209.            
  210.             for _, plr in pairs(playersInGame) do
  211.                 if plr then
  212.                     plr.leaderstats.Cash.Value += config.SurviveReward
  213.                 end
  214.             end
  215.            
  216.         else
  217.             status.Value = "The Juggernaut won by eliminating everyone!"
  218.            
  219.             if juggernaut then
  220.                 juggernaut.leaderstats.Cash.Value += config.JuggernautWinReward
  221.             end
  222.         end
  223.        
  224.        
  225.         for _, plr in pairs(game.Players:GetPlayers()) do
  226.             plr:LoadCharacter()
  227.         end
  228.        
  229.         juggernautHealth:Destroy()
  230.         chosenMap:Destroy()
  231.        
  232.         task.wait(config.RoundEndTime)
  233.     end
  234. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement