vendaskOfficial

voting system with map

Sep 19th, 2020 (edited)
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.54 KB | None | 0 0
  1. --[[
  2. NOTES:
  3. if you want to use this exact script make sure there are 3 parts in workspace
  4. each part should be nammed Button1, Button2 and Button3
  5. each part should have a surfacegui with a textlabel
  6.  
  7. you also need a folder named Maps in replicatedstorage
  8. put at least 3 maps there or else death
  9. create a model in workspace named "Structures"
  10.  
  11. otherwise if you know what you're doing go apes**t i guess
  12. ]]
  13.  
  14. Button1 = game.workspace.Button1
  15. Button2 = game.workspace.Button2
  16. Button3 = game.workspace.Button3
  17.  
  18. --[[
  19. if you dont understand what this does
  20. its a pre-set function before the while true do
  21. it randomly picks the maps in the maps folder
  22. it keeps randomly picking the maps until all of the map variables have different map numbers
  23. it puts them into the table called "tablemap" and then returns the table
  24. which means if you use function obtainmap() it would have the value of the table
  25.  
  26. hope this helps lmao
  27. ]]
  28. function obtainmap()
  29.     local maps = game.ReplicatedStorage.Maps:GetChildren()
  30.     local tablemap = {}
  31.     local good = false -- placeholder
  32.     repeat
  33.         local map1 = math.random(1, #maps)
  34.         local map2 = math.random(1, #maps)
  35.         local map3 = math.random(1, #maps)
  36.         if map3 ~= map2 and map2 ~= map1 and map1 ~= map3 then
  37.             tablemap[1] = map1
  38.             tablemap[2] = map2
  39.             tablemap[3] = map3
  40.             return tablemap
  41.         end
  42.     until good
  43. end
  44.  
  45. while true do
  46.  
  47.     --voting part
  48.  
  49.     game.Workspace.Structures:ClearAllChildren() -- deletes the map at the start of the round
  50.  
  51.     --use obtainmap(), explanation above as well as get the maps
  52.     maptable = obtainmap()
  53.     maps = game.ReplicatedStorage.Maps:GetChildren()
  54.    
  55.     table1 = {}
  56.     table2 = {}
  57.     table3 = {}
  58.    
  59.     text1 = Button1.SurfaceGui.TextLabel
  60.     text2 = Button2.SurfaceGui.TextLabel
  61.     text3 = Button3.SurfaceGui.TextLabel
  62.  
  63.     -- changes the text of the buttons but also has the map name
  64.     text1.Text = maps[maptable[1]].Name .. ": ".. 0
  65.     text2.Text = maps[maptable[2]].Name .. ": ".. 0
  66.     text3.Text = maps[maptable[3]].Name .. ": ".. 0
  67.  
  68.     voting = true
  69.    
  70.     print("start")
  71.  
  72.     Button1.Touched:Connect(function(hit)
  73.         if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") and voting == true then
  74.             local char = hit.Parent
  75.             local plr = game.Players:GetPlayerFromCharacter(char)
  76.             local tableexist = false
  77.             if #table1 > 0 then
  78.                 for b = 1, #table1, 1 do
  79.                     if table1[b] == plr.Name then
  80.                         tableexist = true
  81.                     end
  82.                 end
  83.             end
  84.             if #table2 > 0 then
  85.                 for b = 1, #table2, 1 do
  86.                     if table2[b] == plr.Name then
  87.                         table.remove(table2, b)
  88.                     end
  89.                 end
  90.             end
  91.             if #table3 > 0 then
  92.                 for b = 1, #table3, 1 do
  93.                     if table3[b] == plr.Name then
  94.                         table.remove(table3, b)
  95.                     end
  96.                 end
  97.             end
  98.             if tableexist == false then
  99.                 table1[#table1 + 1] = plr.Name
  100.             end
  101.             text1.Text = maps[maptable[1]].Name .. ": ".. #table1
  102.             text2.Text = maps[maptable[2]].Name .. ": ".. #table2
  103.             text3.Text = maps[maptable[3]].Name .. ": ".. #table3
  104.         end
  105.     end)
  106.     Button2.Touched:Connect(function(hit)
  107.         if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") and voting == true then
  108.             local char = hit.Parent
  109.             local plr = game.Players:GetPlayerFromCharacter(char)
  110.             local tableexist = false
  111.             if #table2 > 0 then
  112.                 for b = 1, #table2, 1 do
  113.                     if table2[b] == plr.Name then
  114.                         tableexist = true
  115.                     end
  116.                 end
  117.             end
  118.             if #table1 > 0 then
  119.                 for b = 1, #table1, 1 do
  120.                     if table1[b] == plr.Name then
  121.                         table.remove(table1, b)
  122.                     end
  123.                 end
  124.             end
  125.             if #table3 > 0 then
  126.                 for b = 1, #table3, 1 do
  127.                     if table3[b] == plr.Name then
  128.                         table.remove(table3, b)
  129.                     end
  130.                 end
  131.             end
  132.             if tableexist == false then
  133.                 table2[#table2 + 1] = plr.Name
  134.             end
  135.             text1.Text = maps[maptable[1]].Name .. ": ".. #table1
  136.             text2.Text = maps[maptable[2]].Name .. ": ".. #table2
  137.             text3.Text = maps[maptable[3]].Name .. ": ".. #table3
  138.         end
  139.     end)
  140.     Button3.Touched:Connect(function(hit)
  141.         if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") and voting == true then
  142.             local char = hit.Parent
  143.             local plr = game.Players:GetPlayerFromCharacter(char)
  144.             local tableexist = false
  145.             if #table3 > 0 then
  146.                 for b = 1, #table3, 1 do
  147.                     if table3[b] == plr.Name then
  148.                         tableexist = true
  149.                     end
  150.                 end
  151.             end
  152.             if #table2 > 0 then
  153.                 for b = 1, #table2, 1 do
  154.                     if table2[b] == plr.Name then
  155.                         table.remove(table2, b)
  156.                     end
  157.                 end
  158.             end
  159.             if #table1 > 0 then
  160.                 for b = 1, #table1, 1 do
  161.                     if table1[b] == plr.Name then
  162.                         table.remove(table1, b)
  163.                     end
  164.                 end
  165.             end
  166.             if tableexist == false then
  167.                 table3[#table3 + 1] = plr.Name
  168.             end
  169.             text1.Text = maps[maptable[1]].Name .. ": ".. #table1
  170.             text2.Text = maps[maptable[2]].Name .. ": ".. #table2
  171.             text3.Text = maps[maptable[3]].Name .. ": ".. #table3
  172.         end
  173.     end)
  174.  
  175.     wait(10)
  176.  
  177.     print("table 1: " .. #table1)
  178.     print("table 2: " .. #table2)
  179.     print("table 3: " .. #table3)
  180.  
  181.     voting = false
  182.  
  183.     winner = 0
  184.  
  185.     values = {
  186.         {"1", #table1};
  187.         {"2", #table2};
  188.         {"3", #table3};
  189.     }
  190.  
  191.     table.sort(values, function(a, b)
  192.         if a[2] > b[2] then
  193.             return true
  194.         end
  195.     end)
  196.  
  197.     if values[1][2] <= 0 then
  198.         winner = math.random(1, 3)
  199.     else
  200.         winner = tonumber(values[1][1])
  201.     end
  202.  
  203.     -- do a specific thing for the specific vote
  204.  
  205.     b = maptable[winner] --get from the table with the winner number
  206.     w = maps[tonumber(b)]:Clone() --clone the winning map
  207.     w.Parent = game.Workspace.Structures -- paste into structures
  208.  
  209.     --end of voting part
  210.    
  211.     wait(5)
  212.  
  213.     --do the rest of the game
  214.    
  215. end
  216.  
  217.  
Add Comment
Please, Sign In to add comment