Advertisement
President_2000

Code Example For map changing

Nov 21st, 2020 (edited)
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.92 KB | None | 0 0
  1. --Game Link: https://www.roblox.com/games/1075564225/Script-Showcase
  2.  
  3. local function RANDOM_MAP_SELECT()
  4. print("---RANDOM MAP SELECTION---")
  5. local MapBool = {"Map1","Map2","Map3","Map4","Map5","Map6","Map7"}
  6. print(table.concat(MapBool,' '))
  7.     for i,v in pairs (MapBool) do
  8.     if i > 4 then return end
  9.     local random = Random.new(tick())
  10.     local randomMap = random:NextInteger(1, #MapBool)
  11.     local map = game:GetService('ReplicatedStorage').Active:WaitForChild(MapBool[randomMap])
  12.     map.Value = true
  13.     map[map.Name]:Clone().Parent = game:GetService('ReplicatedStorage').VoteReady                              
  14.         table.remove(MapBool, randomMap)               
  15.         print(table.concat(MapBool,' '))
  16.     end
  17. end
  18.  
  19.  
  20. local function APPLYING_MAP()
  21. print("---APPLYING MAP SELECTION---")
  22. local MAPS = game:GetService('ReplicatedStorage').VoteReady
  23. local MapsGrab = game.ReplicatedStorage.VoteReady:GetChildren()
  24.  
  25. if MAPS:FindFirstChild(MapsGrab[1].Name).Value == 0 and MAPS:FindFirstChild(MapsGrab[2].Name).Value == 0 and MAPS:FindFirstChild(MapsGrab[3].Name).Value == 0 and MAPS:FindFirstChild(MapsGrab[4].Name).Value == 0 then
  26. print("---NONE HAS VOTED, RESSETTING SYSTEM---")
  27. for i,v in pairs(game:GetService('ReplicatedStorage').Active:GetChildren()) do
  28.     if v.Value == true then
  29.     v.Value = false
  30.     game:GetService('ReplicatedStorage').VoteReady[v.Name]:Destroy()
  31.     end      
  32.     print(i,v.Value)
  33. end
  34. print("---System Resetted---")
  35.  
  36. --Locate The Voted Choice
  37. elseif MAPS:FindFirstChild(MapsGrab[1].Name).Value > MAPS:FindFirstChild(MapsGrab[2].Name).Value and MAPS:FindFirstChild(MapsGrab[3].Name).Value and MAPS:FindFirstChild(MapsGrab[4].Name).Value then
  38. local Choice1Voted = MapsGrab[1].Name
  39. print("Map Voted | "..MapsGrab[1].Name)
  40. --Clear Previous Map Sources
  41. local MapRemoval = {'Map1','Map2','Map3','Map4','Map5','Map6','Map7'}
  42.     for i,v in pairs (MapRemoval) do
  43.         if workspace:FindFirstChild(v) then
  44.             workspace[v]:Destroy()
  45.         end
  46.     end
  47.  
  48. local OrbRemoval = {'OrbSpawns1','OrbSpawns2','OrbSpawns3','OrbSpawns4','OrbSpawns5','OrbSpawns6','OrbSpawns7'}
  49.     for i,v in pairs(OrbRemoval)do
  50.         if workspace:FindFirstChild(v)then
  51.         workspace[v]:Destroy()
  52.         end
  53.     end
  54. local ConfigRemoval = {'Config1','Config2','Config3','Config4','Config5','Config6','Config7'}
  55.     for i,v in pairs (ConfigRemoval) do
  56.         if game:GetService('Lighting'):FindFirstChild(v) then
  57.         game:GetService('Lighting')[v]:Destroy()
  58.         end
  59.     end
  60. local ReplicateRemoval = {'ReplicatedStorage1','ReplicatedStorage2','ReplicatedStorage3','ReplicatedStorage4','ReplicatedStorage5','ReplicatedStorage6','ReplicatedStorage7'}
  61.     for i,v in pairs (ReplicateRemoval) do
  62.         if game:GetService('ReplicatedStorage'):FindFirstChild(v) then
  63.         game:GetService('ReplicatedStorage')[v]:Destroy()
  64.        end
  65.     end
  66.  
  67. if Choice1Voted == "Map1" then
  68.     game:GetService('ServerStorage').Maps.Map1.Map1:Clone().Parent = workspace
  69.     game:GetService('ServerStorage').Maps.Map1.OrbSpawns1:Clone().Parent = workspace
  70.     game:GetService('ServerStorage').Maps.Map1.Config1:Clone().Parent = game:GetService('Lighting')
  71.     game:GetService('ServerStorage').Maps.Map1.ReplicatedStorage1:Clone().Parent = game:GetService('ReplicatedStorage')
  72.     local LightingMover = game:GetService('ServerStorage').Maps.Map1.Lighting1:GetDescendants()
  73.     for i,v in pairs (LightingMover) do
  74.         if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") or v:IsA("BlurEffect") or v:IsA("BloomEffect") or v:IsA("SunRaysEffect") then
  75.             v:Clone().Parent = game:GetService('Lighting')
  76.         end
  77.     end
  78.     plr:LoadCharacter()
  79. elseif Choice1Voted == "Map2" then
  80.     game:GetService('ServerStorage').Maps.Map2.Map2:Clone().Parent = workspace
  81.     game:GetService('ServerStorage').Maps.Map2.OrbSpawns2:Clone().Parent = workspace
  82.     game:GetService('ServerStorage').Maps.Map2.Config2:Clone().Parent = game:GetService('Lighting')
  83.     game:GetService('ServerStorage').Maps.Map2.ReplicatedStorage2:Clone().Parent = game:GetService('ReplicatedStorage')
  84.     local LightingMover = game:GetService('ServerStorage').Maps.Map2.Lighting2:GetDescendants()
  85.     for i,v in pairs (LightingMover) do
  86.         if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") or v:IsA("BlurEffect") or v:IsA("BloomEffect") or v:IsA("SunRaysEffect") then
  87.             v:Clone().Parent =  game:GetService('Lighting')
  88.         end
  89.     end
  90.     plr:LoadCharacter()
  91. elseif Choice2Voted == "Map3" then
  92.     game:GetService('ServerStorage').Maps.Map3.Map3:Clone().Parent = workspace
  93.     game:GetService('ServerStorage').Maps.Map3.OrbSpawns3:Clone().Parent = workspace
  94.     game:GetService('ServerStorage').Maps.Map3.Config3:Clone().Parent = game:GetService('Lighting')
  95.     game:GetService('ServerStorage').Maps.Map3.ReplicatedStorage3:Clone().Parent = game:GetService('ReplicatedStorage')
  96.     local LightingMover = game:GetService('ServerStorage').Maps.Map3.Lighting3:GetDescendants()
  97.     for i,v in pairs (LightingMover) do
  98.        if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") or v:IsA("BlurEffect") or v:IsA("BloomEffect") or v:IsA("SunRaysEffect") then
  99.            v:Clone().Parent = game.Lighting
  100.        end
  101.     end
  102.     plr:LoadCharacter()
  103. elseif Choice2Voted == "Map4" then
  104.     game:GetService('ServerStorage').Maps.Map4.Map4:Clone().Parent = workspace
  105.     game:GetService('ServerStorage').Maps.Map4.OrbSpawns4:Clone().Parent = workspace
  106.     game:GetService('ServerStorage').Maps.Map4.Config4:Clone().Parent = game:GetService('Lighting')
  107.     game:GetService('ServerStorage').Maps.Map4.ReplicatedStorage4:Clone().Parent = game:GetService('ReplicatedStorage')
  108.     local LightingMover = game:GetService('ServerStorage').Maps.Map4.Lighting4:GetDescendants()
  109.     for i,v in pairs (LightingMover) do
  110.         if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") or v:IsA("BlurEffect") or v:IsA("BloomEffect") or v:IsA("SunRaysEffect") then
  111.             v:Clone().Parent =  game:GetService('Lighting')
  112.         end
  113.     end
  114.     plr:LoadCharacter()
  115. elseif Choice2Voted == "Map5" then
  116.     game:GetService('ServerStorage').Maps.Map5.Map5:Clone().Parent = workspace
  117.     game:GetService('ServerStorage').Maps.Map5.OrbSpawns5:Clone().Parent = workspace
  118.     game:GetService('ServerStorage').Maps.Map5.Config5:Clone().Parent = game:GetService('Lighting')
  119.     game:GetService('ServerStorage').Maps.Map5.ReplicatedStorage5:Clone().Parent = game:GetService('ReplicatedStorage')
  120.     local LightingMover = game:GetService('ServerStorage').Maps.Map5.Lighting5:GetDescendants()
  121.     for i,v in pairs (LightingMover) do
  122.         if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") or v:IsA("BlurEffect") or v:IsA("BloomEffect") or v:IsA("SunRaysEffect") then
  123.             v:Clone().Parent =  game:GetService('Lighting')
  124.         end
  125.     end
  126.     plr:LoadCharacter()
  127. elseif Choice2Voted == "Map6" then
  128.     game:GetService('ServerStorage').Maps.Map6.Map6:Clone().Parent = workspace
  129.     game:GetService('ServerStorage').Maps.Map6.OrbSpawns6:Clone().Parent = workspace
  130.     game:GetService('ServerStorage').Maps.Map6.Config6:Clone().Parent = game:GetService('Lighting')
  131.     game:GetService('ServerStorage').Maps.Map6.ReplicatedStorage6:Clone().Parent = game:GetService('ReplicatedStorage')
  132.     local LightingMover = game:GetService('ServerStorage').Maps.Map6.Lighting6:GetDescendants()
  133.     for i,v in pairs (LightingMover) do
  134.         if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") or v:IsA("BlurEffect") or v:IsA("BloomEffect") or v:IsA("SunRaysEffect") then
  135.             v:Clone().Parent = game:GetService('Lighting')
  136.         end
  137.     end
  138.     plr:LoadCharacter()
  139. elseif Choice2Voted == "Map7" then
  140.     game:GetService('ServerStorage').Maps.Map7.Map7:Clone().Parent = workspace
  141.     game:GetService('ServerStorage').Maps.Map7.OrbSpawns7:Clone().Parent = workspace
  142.     game:GetService('ServerStorage').Maps.Map7.Config7:Clone().Parent = game:GetService('Lighting')
  143.     game:GetService('ServerStorage').Maps.Map7.ReplicatedStorage7:Clone().Parent = game:GetService('ReplicatedStorage')
  144.     local LightingMover = game:GetService('ServerStorage').Maps.Map7.Lighting7:GetDescendants()
  145.     for i,v in pairs (LightingMover) do
  146.         if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") or v:IsA("BlurEffect") or v:IsA("BloomEffect") or v:IsA("SunRaysEffect") then
  147.             v:Clone().Parent =  game:GetService('Lighting')
  148.         end
  149.     end
  150.     plr:LoadCharacter()
  151. end
  152. end
  153.  
  154. --//START OF MAP CHANGING\\--  
  155. local PlayerSpeed = game:GetService('ReplicatedStorage').MiscRemotes.PlayerSpeed
  156. local PlayerJump = game:GetService('ReplicatedStorage').MiscRemotes.PlayerJump
  157. local VoteSystemShow = game:GetService('ReplicatedStorage').MiscRemotes.VoteShow
  158. local CanMoveEvent = game:GetService('ReplicatedStorage').MiscRemotes.CanMove
  159. local ResettingVote = game:GetService('ReplicatedStorage').MiscRemotes.ResetVote
  160. --Detect a map initiate--
  161. game:GetService('ReplicatedStorage').InitiateCount.Changed:Connect(function()
  162.     if game:GetService('ReplicatedStorage').Timer.Value == "00:15"then
  163.     local np = game.Players:GetChildren()
  164.     local MaxPlaying = #np
  165.         if game:GetService('ReplicatedStorage').InitiateCount.Value == MaxPlaying then
  166.             game:GetService('ReplicatedStorage').Active.Value = true
  167.             print('Active Map Vote Enabled with'..#np.."Players")
  168.             PlayerJump:FireAllClients(0)
  169.             PlayerSpeed:FireAllClients(0)
  170.             game:GetService('ServerStorage').MapBlur:Clone().Parent = game:GetService('Lighting')
  171.             repeat
  172.             game:GetService('Lighting'):WaitForChild("MapBlur").Size = game:GetService('Lighting').MapBlur.Size +1
  173.         until game:GetService('Lighting').MapBlur.Size >=24
  174.             print("-----------------MAP SYSTEM ENABLED---------------")
  175.             RANDOM_MAP_SELECT()
  176.             VoteSystemShow:FireAllClients(true)
  177.         end
  178.     end
  179. end)
  180.  
  181. game:GetService('ReplicatedStorage').Timer.Changed:Connect(function()
  182.     if game:GetService('ReplicatedStorage').Timer.Value == "00:00" then
  183.     print("-----------------MAP SYSTEM Disabled---------------")
  184.     CanMoveEvent:FireAllClients(true)
  185.     ResettingVote:FireAllClients(false)
  186.     game:GetService('ReplicatedStorage').Active.Value = false
  187.     game:GetService('Lighting'):ClearAllChildren()
  188.     APPLYING_MAP() --This function to apply new map,lighting, and update gui settings is too long(parts of it in pastebin)
  189.     wait(1)
  190.     local CurrentMaps = game:GetService('ReplicatedStorage').VoteReady:GetChildren()
  191.     if #CurrentMaps >=1 then
  192.         for i,v in pairs(game:GetService('ReplicatedStorage').Active:GetChildren()) do
  193.             if  v.Value == true then
  194.                     v.Value = false
  195.                     game:GetService('ReplicatedStorage').VoteReady[v.Name]:Destroy()       
  196.             end    
  197.               print(i,v.Value)
  198.         end
  199.      end
  200.     --Fire Original Values
  201.     wait(2)
  202.     PlayerJump:FireAllClients(50)
  203.     PlayerSpeed:FireAllClients(16)
  204.     VoteSystemShow:FireAllClients(false)
  205.     game:GetService('ReplicatedStorage').InitiateCount.Value = 0
  206.     end
  207. end)
  208.  
  209.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement