Advertisement
HowToRoblox

MapSelectorScript

Nov 16th, 2019
4,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. local players = game:GetService("Players")
  2.  
  3. local length = 30
  4.  
  5. local PlrsAlive = {}
  6.  
  7. players.PlayerAdded:Connect(function(plr)
  8.     plr:LoadCharacter()
  9. end)
  10.  
  11.  
  12. while true do
  13.    
  14.     repeat wait(1) until players.NumPlayers >= 2
  15.    
  16.     wait(5)
  17.    
  18.     local Maps = game:GetService("ServerStorage").Maps:GetChildren()
  19.    
  20.     local ChosenMap = Maps[math.random(1,#Maps)]
  21.    
  22.     map = ChosenMap:Clone()
  23.     map.Parent = workspace
  24.    
  25.    
  26.     local spawns = map:FindFirstChild("Spawns"):GetChildren()
  27.    
  28.     for i, player in pairs(players:GetChildren()) do
  29.         if player.character then
  30.             char = player.character
  31.            
  32.             char:FindFirstChild("HumanoidRootPart").CFrame = spawns[i].CFrame + Vector3.new(0,10,0)
  33.            
  34.             local tag = Instance.new("BoolValue",char)
  35.             tag.Name = "PlayerAlive"
  36.            
  37.             table.insert(PlrsAlive, player)
  38.         end  
  39.     end
  40.  
  41.     for i, x in pairs(game:GetService("ServerStorage").Weapons:GetChildren()) do
  42.         if x.ClassName == "Tool" then
  43.             for i, player in pairs(players:GetChildren()) do
  44.                 x:Clone().Parent = player.Backpack
  45.             end
  46.         end
  47.     end
  48.    
  49.     for i = 0, length do
  50.         wait(1)
  51.         for x, player in pairs(players:GetChildren()) do
  52.             if player then
  53.                 if player.Character then
  54.                     if not player.Character:FindFirstChild("PlayerAlive") then
  55.                         table.remove(PlrsAlive, x)
  56.                     end
  57.                 end
  58.             else
  59.                 table.remove(PlrsAlive, x)
  60.             end
  61.         end
  62.         if #PlrsAlive < 2 then break end       
  63.     end
  64.    
  65.    
  66.     for i, player in pairs(players:GetChildren()) do
  67.        
  68.         for i, tool in pairs(player.Backpack:GetChildren()) do
  69.             tool:Destroy()
  70.         end
  71.        
  72.         if player.Character:FindFirstChild("PlayerAlive") then
  73.             player.Character:FindFirstChild("PlayerAlive"):Destroy()
  74.         end
  75.         player:LoadCharacter()
  76.     end    
  77.     map:Destroy()
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement