Advertisement
HowToRoblox

MapVoteHandler

May 9th, 2020
6,659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 KB | None | 0 0
  1. local pads = script.Parent.MapVotePads
  2.  
  3. local mapBoards = script.Parent.MapBoards
  4.  
  5. local votingStatus = script.Parent.VotingStatus
  6.  
  7.  
  8. local canVote = false
  9.  
  10.  
  11. local maps =
  12. {
  13.     Map1 = 1515986593,
  14.     Map2 = 177925016,
  15.     Map3 = 956900746,
  16.     Map4 = 47346541,
  17.     Map5 = 1389476778,
  18.     Map6 = 873393577,
  19. }
  20.  
  21.  
  22. while true do
  23.    
  24.     pads.MapVote1.Votes:ClearAllChildren()
  25.     pads.MapVote2.Votes:ClearAllChildren()
  26.     pads.MapVote3.Votes:ClearAllChildren()
  27.    
  28.     pads.MapVote1.VotedGui.VotedAmount.Text = ""
  29.     pads.MapVote2.VotedGui.VotedAmount.Text = ""
  30.     pads.MapVote3.VotedGui.VotedAmount.Text = ""
  31.    
  32.     mapBoards.Map1.MapGui.MapImage.ImageTransparency = 1
  33.     mapBoards.Map2.MapGui.MapImage.ImageTransparency = 1
  34.     mapBoards.Map3.MapGui.MapImage.ImageTransparency = 1
  35.    
  36.     mapBoards.Map1.MapGui.MapName.Text = ""
  37.     mapBoards.Map2.MapGui.MapName.Text = ""
  38.     mapBoards.Map3.MapGui.MapName.Text = ""
  39.    
  40.     for i = 5, 0, -1 do
  41.        
  42.         votingStatus.StatusGui.Status.Text = "Voting will begin in " .. i .. " seconds"
  43.        
  44.         wait(1)
  45.     end
  46.    
  47.    
  48.     votingStatus.StatusGui.Status.Text = "Vote for the map"
  49.    
  50.    
  51.     local keysTable = {}
  52.     for key, value in pairs(maps) do
  53.         table.insert(keysTable, key)
  54.     end
  55.    
  56.     local randomKey1 = keysTable[math.random(#keysTable)]
  57.     local mapChosen1 = maps[randomKey1]
  58.    
  59.     local randomKey2, mapChosen2
  60.     repeat
  61.         randomKey2 = keysTable[math.random(#keysTable)]
  62.         mapChosen2 = maps[randomKey2]
  63.     until mapChosen2 ~= mapChosen1
  64.    
  65.     local randomKey3, mapChosen3
  66.     repeat
  67.         randomKey3 = keysTable[math.random(#keysTable)]
  68.         mapChosen3 = maps[randomKey3]
  69.     until mapChosen3 ~= mapChosen1 and mapChosen3 ~= mapChosen2
  70.    
  71.    
  72.     mapBoards.Map1.MapGui.MapImage.ImageTransparency = 0
  73.     mapBoards.Map2.MapGui.MapImage.ImageTransparency = 0
  74.     mapBoards.Map3.MapGui.MapImage.ImageTransparency = 0
  75.    
  76.     mapBoards.Map1.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen1
  77.     mapBoards.Map2.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen2
  78.     mapBoards.Map3.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen3
  79.    
  80.     mapBoards.Map1.MapGui.MapName.Text = randomKey1
  81.     mapBoards.Map2.MapGui.MapName.Text = randomKey2
  82.     mapBoards.Map3.MapGui.MapName.Text = randomKey3
  83.    
  84.    
  85.     pads.MapVote1.VotedGui.VotedAmount.Text = "0"
  86.     pads.MapVote2.VotedGui.VotedAmount.Text = "0"
  87.     pads.MapVote3.VotedGui.VotedAmount.Text = "0"
  88.    
  89.     canVote = true
  90.    
  91.    
  92.     local function onPadTouched(touch, pad)
  93.         if not canVote then return end
  94.         if game.Players:GetPlayerFromCharacter(touch.Parent) then
  95.            
  96.             if pads.MapVote1.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
  97.                 pads.MapVote1.Votes[game.Players:GetPlayerFromCharacter(touch.Parent).Name]:Destroy()
  98.             end
  99.             if pads.MapVote2.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
  100.                 pads.MapVote2.Votes[game.Players:GetPlayerFromCharacter(touch.Parent).Name]:Destroy()
  101.             end
  102.             if pads.MapVote3.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
  103.                 pads.MapVote3.Votes[game.Players:GetPlayerFromCharacter(touch.Parent).Name]:Destroy()
  104.             end
  105.        
  106.             local touchVal = Instance.new("StringValue")
  107.             touchVal.Name = game.Players:GetPlayerFromCharacter(touch.Parent).Name
  108.             touchVal.Parent = pad.Votes
  109.            
  110.             pads.MapVote1.VotedGui.VotedAmount.Text = #pads.MapVote1.Votes:GetChildren()
  111.             pads.MapVote2.VotedGui.VotedAmount.Text = #pads.MapVote2.Votes:GetChildren()
  112.             pads.MapVote3.VotedGui.VotedAmount.Text = #pads.MapVote3.Votes:GetChildren()
  113.         end
  114.     end
  115.    
  116.     pads.MapVote1.Touched:Connect(function(touch)
  117.         onPadTouched(touch, pads.MapVote1)
  118.     end)
  119.     pads.MapVote2.Touched:Connect(function(touch)
  120.         onPadTouched(touch, pads.MapVote2)
  121.     end)
  122.     pads.MapVote3.Touched:Connect(function(touch)
  123.         onPadTouched(touch, pads.MapVote3)
  124.     end)
  125.    
  126.     wait(10)
  127.    
  128.     canVote = false
  129.    
  130.    
  131.     local highestVoted
  132.    
  133.     for i, pad in pairs(pads:GetChildren()) do
  134.        
  135.         if not highestVoted then highestVoted = pad end
  136.        
  137.         if #pad.Votes:GetChildren() > #highestVoted.Votes:GetChildren() then
  138.            
  139.             highestVoted = pad
  140.            
  141.         elseif #pad.Votes:GetChildren() == #highestVoted.Votes:GetChildren() then
  142.            
  143.             local mapsToChoose = {pad, highestVoted}
  144.             highestVoted = mapsToChoose[math.random(#mapsToChoose)]
  145.         end
  146.     end
  147.    
  148.     local mapName = mapBoards["Map" .. string.gsub(highestVoted.Name, "MapVote", "")].MapGui.MapName.Text
  149.     votingStatus.StatusGui.Status.Text = mapName .. " has been voted"
  150.    
  151.     wait(5)
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement