SHARE
TWEET

Untitled

a guest Aug 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Define variables
  2.  
  3. local RepilcatedStorage = game:GetService("ReplicatedStorage")
  4. local ServerStorage = game:GetService("ServerStorage")
  5. local MapsFolder = RepilcatedStorage:WaitForChild("Maps")
  6. local Status = RepilcatedStorage:WaitForChild("Status")
  7. local GameLength = 60
  8. local reward = 100
  9. -- Game Loop
  10.  
  11. while true do
  12.     Status.Value = "Waiting for enough players"
  13.    
  14.     repeat wait(1) until game.Players.NumPlayers >= 2
  15.    
  16.     Status.Value = "Intermission"
  17.     wait(10)
  18.     local plrs = {}
  19.    
  20.     for i, player in pairs(game.Players:GetPlayers()) do
  21.         if player then
  22.             table.insert(plrs,player) --Add each player to plrs table
  23.         end
  24.     end
  25.    
  26.     wait(2)
  27.     local mapTable = {}
  28. for i,v in pairs(game:GetService("ReplicatedStorage").Maps:GetChildren()) do
  29.     table.insert(mapTable, v)
  30. end
  31. local chooseMap = mapTable[math.random(1, #mapTable)]:Clone()
  32. chooseMap.Parent = workspace --// Puts all maps into a table, and chooses random one
  33.        
  34. local mapSpawns = {}
  35. for i,v in pairs(chooseMap.Spawns:GetChildren()) do
  36.     table.insert(mapSpawns, v)
  37. end --// Puts all map spawns into a table
  38.  
  39. local function checkForMapLoaded(ClonedMap, OriginalMap)
  40.    local function checkForMapLoaded(ClonedMap, OriginalMap)
  41.     local OriginalMapTable = OriginalMap:GetChildren()
  42.  
  43.     for i, part in pairs(OriginalMapTable) do
  44.         local LoadingPart = ClonedMap:WaitForChild(part.Name)
  45.         table.remove(mapTable, i)
  46.     end
  47. end
  48.  
  49.  
  50. checkForMapLoaded(chooseMap, MapsFolder:FindFirstChild(chooseMap.Name))
  51. end --// Teleports all players to a random spawn
  52.  
  53.     for i, player in pairs(plrs) do
  54.         if player then
  55.             local character = player.Character
  56.             if character then
  57.                 -- Teleport them
  58.                
  59.                 -- Give them a sword
  60.                
  61.                 local Sword = ServerStorage.Sword:Clone()
  62.                 Sword.Parent = player.Backpack
  63.                
  64.                 local GameTag = Instance.new("BoolValue")
  65.                 GameTag.Name = "GameTag"
  66.                 GameTag.Parent = player.Character
  67.             else
  68.                 -- There is no character
  69.                 if not player then
  70.                     table.remove(plrs,1)
  71.                 end
  72.             end
  73.         end
  74.     end
  75.    
  76.     Status.Value = "Get Ready to Play!"
  77.     wait(2)
  78.    
  79.     for i = GameLength,0,-1 do
  80.        
  81.         for x, player in pairs(plrs) do
  82.             if player then
  83.                
  84.                 local character = player.Character
  85.                
  86.                 if not character then
  87.                     -- Left the game
  88.                     table.remove(plrs, x)
  89.                 else
  90.                     if character:FindFirstChild("GameTag") then
  91.                         --They  are still alive
  92.                         print(player.Name.." is still in the game!")
  93.                     else
  94.                         -- They are dead
  95.                         table.remove(plrs,x)
  96.                         print(player.Name.." has been removed!")
  97.  
  98.                     end
  99.                 end
  100.                
  101.             else
  102.                 table.remove(plrs,x)
  103.                 print(player.Name.." has been removed!")
  104.                
  105.                
  106.             end
  107.         end
  108.        
  109.         Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"
  110.        
  111.         if #plrs == 1 then
  112.             -- Last Person Standing
  113.             Status.Value = "The winner is "..plrs[1].Name
  114.             plrs[1].leaderstats.Bucks.Value = plrs[1].leaderstats.Bucks.Value + reward
  115.             break
  116.         elseif #plrs == 0 then
  117.             Status.Value = "Nobody won!"
  118.         elseif i == 0 then
  119.             Status.Value = "Time up!"
  120.             break
  121.         end
  122.        
  123.         wait(3)
  124.     end
  125.    
  126.     print("End of game")
  127.    
  128.     wait(2)
  129.    
  130.     for i, player in pairs(game.Players:GetPlayers()) do
  131.         character = player.Character
  132.        
  133.         if not character then
  134.             -- Ignore them
  135.         else
  136.             if character:FindFirstChild("GameTag") then
  137.                 character.GameTag:Destroy()
  138.             end
  139.            
  140.             if player.Backpack:FindFirstChild("Sword") then
  141.                 player.Backpack.Sword:Destroy()
  142.             end
  143.            
  144.            
  145.             if character:FindFirstChild("Sword") then
  146.                 character.Sword:Destroy()
  147.             end
  148.            
  149.         end
  150.        
  151.         player:LoadCharacter()
  152.     end
  153.    
  154.     chooseMap:Destroy()
  155.    
  156.     Status.Value = "Game Ended"
  157.    
  158.     wait(2)
  159. 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
 
Top