Mryeetmemes

MapSelector Script for Roblox Studio

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