Advertisement
l_proxl

Untitled

May 19th, 2024
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.91 KB | None | 0 0
  1. local Players = game.Players
  2. local Players2 = Players:GetChildren()
  3.  
  4. local PlayerCount = script.PlayerCount
  5.  
  6. local RedPlayer = nil
  7. local BluePlayer = nil
  8. local OtherPlayer = nil
  9. local HigherThan4=false
  10. local gameStarted = false
  11. local redVotes = 0
  12. local blueVotes = 0
  13. local otherVotes = 0
  14.  
  15. local RedTeamList = {}
  16. local BlueTeamList = {}
  17. local OtherTeamList = {}
  18. local StartFunc
  19.  
  20.  
  21. --function ChooseType(t, playerRandomizer3, playerRandomizer2, textUI)
  22. --  local tB = t
  23. --  local plrRand3B = playerRandomizer3
  24. --  local plrRand2B = playerRandomizer2
  25. --  local textUIB = textUI
  26.  
  27. --  if t == 1 then
  28. --      BluePlayer = nil
  29. --      playerRandomizer2 = Players:GetPlayers()[math.random(1, PlayerCount.Value)]
  30. --      if playerRandomizer2 ~= RedPlayer then
  31. --          textUI:WaitForChild("TextLabel").Text = "Player: "..playerRandomizer2.DisplayName.." (@"..playerRandomizer2.Name..")"
  32. --          BluePlayer= playerRandomizer2
  33. --          return
  34. --      else
  35. --          ChooseType(tB, plrRand3B, plrRand2B, textUIB)
  36. --      end
  37.  
  38. --  elseif t == 2 then
  39. --      OtherPlayer = nil
  40. --      playerRandomizer3 = Players:GetPlayers()[math.random(1, PlayerCount.Value)]
  41. --      if playerRandomizer3 == RedPlayer then
  42. --          ChooseType(tB, plrRand3B, plrRand2B, textUIB)
  43. --      elseif playerRandomizer3 == BluePlayer then
  44. --          ChooseType(tB, plrRand3B, plrRand2B, textUIB)
  45. --      else
  46. --          textUI:WaitForChild("TextLabel").Text = "Player: "..playerRandomizer3.DisplayName.." (@"..playerRandomizer3.Name..")"
  47. --          OtherPlayer= playerRandomizer3
  48. --          return
  49. --      end
  50.  
  51. --  end
  52. --end
  53.  
  54.  
  55. function StartGame(Player: Player, TextUI, SpeakingUI)
  56.     local TextLabel = TextUI:WaitForChild("TextLabel")
  57.     RedPlayer.Character.Humanoid.Jump = true
  58.     BluePlayer.Character.Humanoid.Jump = true
  59.     OtherPlayer.Character.Humanoid.Jump = true
  60.    
  61.     task.wait(0.2)
  62.  
  63.     RedPlayer.Character.HumanoidRootPart.CFrame = workspace.TP1.CFrame
  64.     BluePlayer.Character.HumanoidRootPart.CFrame = workspace.TP2.CFrame
  65.     OtherPlayer.Character.HumanoidRootPart.CFrame = workspace.TP3.CFrame
  66.  
  67.     RedPlayer.Character.Humanoid.WalkSpeed = 0
  68.     BluePlayer.Character.Humanoid.WalkSpeed = 0
  69.     OtherPlayer.Character.Humanoid.WalkSpeed = 0
  70.  
  71.     RedPlayer.Character.Humanoid.JumpPower = 0
  72.     BluePlayer.Character.Humanoid.JumpPower = 0
  73.     OtherPlayer.Character.Humanoid.JumpPower = 0
  74.  
  75.     RedPlayer.PlayerGui.TeamSelection.Enabled = false
  76.     BluePlayer.PlayerGui.TeamSelection.Enabled = false
  77.     OtherPlayer.PlayerGui.TeamSelection.Enabled = false
  78.  
  79.  
  80.     gameStarted = true
  81.     SpeakingUI.Enabled = true
  82.  
  83.     SpeakingUI:WaitForChild("Frame"):WaitForChild("Name").Text = RedPlayer.DisplayName.." (@"..RedPlayer.Name..")"
  84.     local connection
  85.     connection = RedPlayer.Chatted:Connect(function(msg)
  86.         SpeakingUI:WaitForChild("Frame"):WaitForChild("Chat").Text = msg
  87.     end)
  88.  
  89.     game.ReplicatedStorage.MuteUser:FireClient(BluePlayer)
  90.     game.ReplicatedStorage.MuteUser:FireClient(OtherPlayer)
  91.     game.ReplicatedStorage.UnmuteUser:FireClient(RedPlayer)
  92.  
  93.  
  94.     for i = 90,0,-1 do
  95.         TextLabel.Text = "It's time for red team to start talking, you have "..i.." seconds."
  96.         wait(1)
  97.     end
  98.  
  99.     connection:Disconnect()
  100.  
  101.     SpeakingUI:WaitForChild("Frame"):WaitForChild("Name").Text = BluePlayer.DisplayName.." (@"..BluePlayer.Name..")"
  102.  
  103.     local connection2
  104.  
  105.     connection2 = BluePlayer.Chatted:Connect(function(msg)
  106.         SpeakingUI:WaitForChild("Frame"):WaitForChild("Chat").Text = msg
  107.     end)
  108.  
  109.     game.ReplicatedStorage.MuteUser:FireClient(OtherPlayer)
  110.     game.ReplicatedStorage.MuteUser:FireClient(RedPlayer)
  111.     game.ReplicatedStorage.UnmuteUser:FireClient(BluePlayer)
  112.  
  113.  
  114.     for i = 90,0,-1 do
  115.         TextLabel.Text = "It's time for blue team to start talking, you have "..i.." seconds."
  116.         wait(1)
  117.     end
  118.  
  119.     connection2:Disconnect()
  120.     SpeakingUI:WaitForChild("Frame"):WaitForChild("Name").Text = OtherPlayer.DisplayName.." (@"..OtherPlayer.Name..")"
  121.  
  122.     local connection3
  123.  
  124.     connection3 = OtherPlayer.Chatted:Connect(function(msg)
  125.         SpeakingUI:WaitForChild("Frame"):WaitForChild("Chat").Text = msg
  126.     end)
  127.  
  128.     game.ReplicatedStorage.MuteUser:FireClient(BluePlayer)
  129.     game.ReplicatedStorage.MuteUser:FireClient(RedPlayer)
  130.     game.ReplicatedStorage.UnmuteUser:FireClient(OtherPlayer)
  131.  
  132.  
  133.     for i = 90,0,-1 do
  134.         TextLabel.Text = "It's time for other team to start talking, you have "..i.." seconds."
  135.         wait(1)
  136.     end
  137.  
  138.  
  139.     SpeakingUI.Enabled = false
  140.  
  141.     connection3:Disconnect()
  142.  
  143.     TextLabel.Text = "Now it's time to choose, Who do you want to be the new president?"
  144.  
  145.     local VotingUI
  146.     for i,v in pairs(game.Players:GetPlayers()) do
  147.         VotingUI = v.PlayerGui:WaitForChild("VotingUI")
  148.         VotingUI.VoteFrame.Visible = true
  149.     end
  150.  
  151.     game.ReplicatedStorage.UnmuteUser:FireAllClients()
  152.  
  153.     VotingUI:WaitForChild("VoteFrame").Visible = true
  154.     BluePlayer.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
  155.     RedPlayer.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
  156.     OtherPlayer.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
  157.  
  158.  
  159.     VotingUI.VoteFrame.Blue.Text = BluePlayer.DisplayName.." (@"..BluePlayer.Name..")"
  160.     VotingUI.VoteFrame.Red.Text = RedPlayer.DisplayName.." (@"..RedPlayer.Name..")"
  161.     VotingUI.VoteFrame.Other.Text = OtherPlayer.DisplayName.." (@"..OtherPlayer.Name..")"
  162.  
  163.     game.ReplicatedStorage.VoteResults.OnServerEvent:Connect(function(T)
  164.         if T == 1 then
  165.             redVotes += 1
  166.  
  167.         elseif T == 2 then
  168.             blueVotes += 1
  169.  
  170.         elseif T == 3 then
  171.             otherVotes += 1
  172.  
  173.         end
  174.     end)
  175.  
  176.     wait(10)
  177.  
  178.     if redVotes > blueVotes and redVotes > otherVotes then
  179.         TextLabel.Text = "Player (@"..RedPlayer.Name..") won with "..redVotes.." votes!"
  180.         RedPlayer:WaitForChild("leaderstats").Votes.Value += redVotes
  181.         RedPlayer:WaitForChild("leaderstats").Wins.Value += 1
  182.     elseif blueVotes > redVotes and blueVotes> otherVotes then
  183.         TextLabel.Text = "Player (@"..BluePlayer.Name..") won with "..blueVotes.." votes!"
  184.         BluePlayer:WaitForChild("leaderstats").Votes.Value += blueVotes
  185.         BluePlayer:WaitForChild("leaderstats").Wins.Value += 1
  186.     elseif otherVotes > redVotes and otherVotes > blueVotes then
  187.         TextLabel.Text = "Player (@"..OtherPlayer.Name..") won with "..otherVotes.." votes!"
  188.         OtherPlayer:WaitForChild("leaderstats").Votes.Value += otherVotes
  189.         OtherPlayer:WaitForChild("leaderstats").Wins.Value += 1
  190.     elseif redVotes == blueVotes and redVotes == otherVotes then
  191.         TextLabel.Text = "It was a tie!"
  192.         OtherPlayer:WaitForChild("leaderstats").Votes.Value += otherVotes
  193.         BluePlayer:WaitForChild("leaderstats").Votes.Value += blueVotes
  194.         RedPlayer:WaitForChild("leaderstats").Votes.Value += redVotes
  195.     else
  196.         TextLabel.Text = "No one voted."
  197.  
  198.     end
  199.  
  200.  
  201.     task.wait(3)
  202.     endGame(Player)
  203.  
  204.     task.wait(3)
  205.     local TeamsUI
  206.     for i,v in pairs(game.Players:GetPlayers()) do
  207.         TeamsUI = v.PlayerGui:WaitForChild("TeamSelection")
  208.     end
  209.     Intermission(Player, TextUI,TeamsUI)
  210.     return
  211.  
  212. end
  213.  
  214.  
  215. function endGame(player: Player)
  216.     local TextUI
  217.     for i,v in pairs(game.Players:GetPlayers()) do
  218.         game.ReplicatedStorage.UnmuteUser:FireAllClients()
  219.         TextUI = v.PlayerGui:WaitForChild("TextUI")
  220.     end
  221.     local TeamsUI
  222.     for i,v in pairs(game.Players:GetPlayers()) do
  223.         TeamsUI = v.PlayerGui:WaitForChild("TeamSelection")
  224.     end
  225.     for i,v in pairs(game.Players:GetPlayers()) do
  226.         v.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
  227.     end
  228.     RedPlayer = nil
  229.     BluePlayer = nil
  230.     OtherPlayer = nil
  231.     HigherThan4=false
  232.     gameStarted = false
  233.     RedTeamList = {}
  234.     BlueTeamList = {}
  235.     OtherTeamList = {}
  236.     redVotes = 0
  237.     blueVotes = 0
  238.     otherVotes = 0
  239.     if StartFunc ~= nil then
  240.         StartFunc:Disconnect()
  241.         StartFunc = nil
  242.     else
  243.         -- nothing
  244.     end
  245.  
  246.     for i,v in pairs(game.Players:GetPlayers()) do
  247.         v:LoadCharacter()
  248.     end
  249.     TeamsUI.Enabled = true
  250. end
  251.  
  252.  
  253. function Intermission(Player: Player, TextUI, TeamsUI)
  254.     if StartFunc ~= nil then
  255.         StartFunc:Disconnect()
  256.         StartFunc = nil
  257.     else
  258.         wait()
  259.     end
  260.     RedPlayer = nil
  261.     BluePlayer = nil
  262.     OtherPlayer = nil
  263.     HigherThan4=false
  264.     gameStarted = false
  265.     RedTeamList = {}
  266.     BlueTeamList = {}
  267.     OtherTeamList = {}
  268.     redVotes = 0
  269.     blueVotes = 0
  270.     otherVotes = 0
  271.  
  272.  
  273. HigherThan4 = true
  274.     print("Player added. "..Player.Name )
  275.  
  276.     while #game.Teams.Blue:GetPlayers() == 0 or #game.Teams.Other:GetPlayers() == 0 or #game.Teams.Red:GetPlayers() == 0 do
  277.         wait()
  278.     end
  279.     for i, v in pairs(game.Players:GetPlayers()) do
  280.         if v.Team == game.Teams.Red then
  281.             table.insert(RedTeamList, v)
  282.         elseif v.Team == game.Teams.Blue then
  283.             table.insert(BlueTeamList, v)
  284.         elseif v.Team == game.Teams.Other then
  285.             table.insert(OtherTeamList, v)
  286.         end
  287.     end
  288.     print(RedTeamList[1])
  289.     print(BlueTeamList[1])
  290.     print(OtherTeamList[1])
  291.  
  292.     --HigherThan4 = true
  293.     TextUI:WaitForChild("TextLabel").Text = "Choosing a candidate for red team..."
  294.     local PlayerRandomizer = game.Teams.Red:GetPlayers()[math.random(1, #RedTeamList)] -- Players:GetPlayers()
  295.     task.wait(3)
  296.     TeamsUI.Enabled = false
  297.  
  298.     RedPlayer = PlayerRandomizer
  299.     TextUI:WaitForChild("TextLabel").Text = "Player: "..PlayerRandomizer.DisplayName.." (@"..PlayerRandomizer.Name..")"
  300.  
  301.     task.wait(2)
  302.  
  303.     TextUI:WaitForChild("TextLabel").Text = "Choosing a candidate for blue team..."
  304.     local PlayerRandomizer2 = game.Teams.Blue:GetPlayers()[math.random(1, #BlueTeamList)]
  305.     task.wait(3)
  306.  
  307.    
  308.  
  309.     BluePlayer = PlayerRandomizer2
  310.     TextUI:WaitForChild("TextLabel").Text = "Player: "..PlayerRandomizer2.DisplayName.." (@"..PlayerRandomizer2.Name..")"
  311.  
  312.     task.wait(2)
  313.  
  314.     TextUI:WaitForChild("TextLabel").Text = "Choosing a candidate for other team..."
  315.     local PlayerRandomizer3 = game.Teams.Other:GetPlayers()[math.random(1, #OtherTeamList)]
  316.     task.wait(3)
  317.    
  318.     OtherPlayer = PlayerRandomizer3
  319.     TextUI:WaitForChild("TextLabel").Text = "Player: "..PlayerRandomizer3.DisplayName.." (@"..PlayerRandomizer3.Name..")"
  320.  
  321.     task.wait(2)
  322.  
  323.     if RedPlayer ~= nil and BluePlayer ~=nil and OtherPlayer ~=nil then
  324.  
  325.         local SpeakingUI
  326.         for i,v in pairs(game.Players:GetPlayers()) do
  327.             SpeakingUI = v.PlayerGui:WaitForChild("Speaking")
  328.         end
  329.         SpeakingUI.Enabled = true
  330.         local StartFunc = StartGame(Player, TextUI, SpeakingUI)
  331.     else
  332.         print("Something went wrong..")
  333.         return
  334.  
  335.     end
  336.  
  337.  
  338.  
  339.  
  340. end
  341.  
  342. Players.PlayerAdded:Connect(function(Player)
  343.     PlayerCount.Value += 1
  344.     local TextUI
  345.     for i,v in pairs(game.Players:GetPlayers()) do
  346.         TextUI = v.PlayerGui:WaitForChild("TextUI")
  347.     end
  348.     local TeamsUI
  349.     for i,v in pairs(game.Players:GetPlayers()) do
  350.         TeamsUI = v.PlayerGui:WaitForChild("TeamSelection")
  351.     end
  352.    
  353.     Player.PlayerGui:WaitForChild("TextUI"):WaitForChild("TextLabel").Text = TextUI:WaitForChild("TextLabel").Text
  354.  
  355.     while PlayerCount.Value < 4 do
  356.        
  357.         wait()
  358.     end
  359.    
  360.     while HigherThan4 do
  361.         wait()
  362.     end
  363.    
  364.     Intermission(Player, TextUI, TeamsUI)
  365.  
  366. end)
  367.  
  368.  
  369. Players.PlayerRemoving:Connect(function(player)
  370.     PlayerCount.Value -= 1
  371.     local TextUI
  372.     for i,v in pairs(game.Players:GetPlayers()) do
  373.         TextUI = v.PlayerGui:WaitForChild("TextUI")
  374.     end
  375.    
  376.     if player == RedPlayer or player == BluePlayer or player == OtherPlayer then
  377.         print("Player removed. "..player.Name)
  378.         TextUI:WaitForChild("TextLabel").Text = "One of the candidates left, restarting.."
  379.         endGame(player)
  380.        
  381.     end
  382. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement