Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game.Players
- local Players2 = Players:GetChildren()
- local PlayerCount = script.PlayerCount
- local RedPlayer = nil
- local BluePlayer = nil
- local OtherPlayer = nil
- local HigherThan4=false
- local gameStarted = false
- local redVotes = 0
- local blueVotes = 0
- local otherVotes = 0
- local RedTeamList = {}
- local BlueTeamList = {}
- local OtherTeamList = {}
- local StartFunc
- --function ChooseType(t, playerRandomizer3, playerRandomizer2, textUI)
- -- local tB = t
- -- local plrRand3B = playerRandomizer3
- -- local plrRand2B = playerRandomizer2
- -- local textUIB = textUI
- -- if t == 1 then
- -- BluePlayer = nil
- -- playerRandomizer2 = Players:GetPlayers()[math.random(1, PlayerCount.Value)]
- -- if playerRandomizer2 ~= RedPlayer then
- -- textUI:WaitForChild("TextLabel").Text = "Player: "..playerRandomizer2.DisplayName.." (@"..playerRandomizer2.Name..")"
- -- BluePlayer= playerRandomizer2
- -- return
- -- else
- -- ChooseType(tB, plrRand3B, plrRand2B, textUIB)
- -- end
- -- elseif t == 2 then
- -- OtherPlayer = nil
- -- playerRandomizer3 = Players:GetPlayers()[math.random(1, PlayerCount.Value)]
- -- if playerRandomizer3 == RedPlayer then
- -- ChooseType(tB, plrRand3B, plrRand2B, textUIB)
- -- elseif playerRandomizer3 == BluePlayer then
- -- ChooseType(tB, plrRand3B, plrRand2B, textUIB)
- -- else
- -- textUI:WaitForChild("TextLabel").Text = "Player: "..playerRandomizer3.DisplayName.." (@"..playerRandomizer3.Name..")"
- -- OtherPlayer= playerRandomizer3
- -- return
- -- end
- -- end
- --end
- function StartGame(Player: Player, TextUI, SpeakingUI)
- local TextLabel = TextUI:WaitForChild("TextLabel")
- RedPlayer.Character.Humanoid.Jump = true
- BluePlayer.Character.Humanoid.Jump = true
- OtherPlayer.Character.Humanoid.Jump = true
- task.wait(0.2)
- RedPlayer.Character.HumanoidRootPart.CFrame = workspace.TP1.CFrame
- BluePlayer.Character.HumanoidRootPart.CFrame = workspace.TP2.CFrame
- OtherPlayer.Character.HumanoidRootPart.CFrame = workspace.TP3.CFrame
- RedPlayer.Character.Humanoid.WalkSpeed = 0
- BluePlayer.Character.Humanoid.WalkSpeed = 0
- OtherPlayer.Character.Humanoid.WalkSpeed = 0
- RedPlayer.Character.Humanoid.JumpPower = 0
- BluePlayer.Character.Humanoid.JumpPower = 0
- OtherPlayer.Character.Humanoid.JumpPower = 0
- RedPlayer.PlayerGui.TeamSelection.Enabled = false
- BluePlayer.PlayerGui.TeamSelection.Enabled = false
- OtherPlayer.PlayerGui.TeamSelection.Enabled = false
- gameStarted = true
- SpeakingUI.Enabled = true
- SpeakingUI:WaitForChild("Frame"):WaitForChild("Name").Text = RedPlayer.DisplayName.." (@"..RedPlayer.Name..")"
- local connection
- connection = RedPlayer.Chatted:Connect(function(msg)
- SpeakingUI:WaitForChild("Frame"):WaitForChild("Chat").Text = msg
- end)
- game.ReplicatedStorage.MuteUser:FireClient(BluePlayer)
- game.ReplicatedStorage.MuteUser:FireClient(OtherPlayer)
- game.ReplicatedStorage.UnmuteUser:FireClient(RedPlayer)
- for i = 90,0,-1 do
- TextLabel.Text = "It's time for red team to start talking, you have "..i.." seconds."
- wait(1)
- end
- connection:Disconnect()
- SpeakingUI:WaitForChild("Frame"):WaitForChild("Name").Text = BluePlayer.DisplayName.." (@"..BluePlayer.Name..")"
- local connection2
- connection2 = BluePlayer.Chatted:Connect(function(msg)
- SpeakingUI:WaitForChild("Frame"):WaitForChild("Chat").Text = msg
- end)
- game.ReplicatedStorage.MuteUser:FireClient(OtherPlayer)
- game.ReplicatedStorage.MuteUser:FireClient(RedPlayer)
- game.ReplicatedStorage.UnmuteUser:FireClient(BluePlayer)
- for i = 90,0,-1 do
- TextLabel.Text = "It's time for blue team to start talking, you have "..i.." seconds."
- wait(1)
- end
- connection2:Disconnect()
- SpeakingUI:WaitForChild("Frame"):WaitForChild("Name").Text = OtherPlayer.DisplayName.." (@"..OtherPlayer.Name..")"
- local connection3
- connection3 = OtherPlayer.Chatted:Connect(function(msg)
- SpeakingUI:WaitForChild("Frame"):WaitForChild("Chat").Text = msg
- end)
- game.ReplicatedStorage.MuteUser:FireClient(BluePlayer)
- game.ReplicatedStorage.MuteUser:FireClient(RedPlayer)
- game.ReplicatedStorage.UnmuteUser:FireClient(OtherPlayer)
- for i = 90,0,-1 do
- TextLabel.Text = "It's time for other team to start talking, you have "..i.." seconds."
- wait(1)
- end
- SpeakingUI.Enabled = false
- connection3:Disconnect()
- TextLabel.Text = "Now it's time to choose, Who do you want to be the new president?"
- local VotingUI
- for i,v in pairs(game.Players:GetPlayers()) do
- VotingUI = v.PlayerGui:WaitForChild("VotingUI")
- VotingUI.VoteFrame.Visible = true
- end
- game.ReplicatedStorage.UnmuteUser:FireAllClients()
- VotingUI:WaitForChild("VoteFrame").Visible = true
- BluePlayer.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
- RedPlayer.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
- OtherPlayer.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
- VotingUI.VoteFrame.Blue.Text = BluePlayer.DisplayName.." (@"..BluePlayer.Name..")"
- VotingUI.VoteFrame.Red.Text = RedPlayer.DisplayName.." (@"..RedPlayer.Name..")"
- VotingUI.VoteFrame.Other.Text = OtherPlayer.DisplayName.." (@"..OtherPlayer.Name..")"
- game.ReplicatedStorage.VoteResults.OnServerEvent:Connect(function(T)
- if T == 1 then
- redVotes += 1
- elseif T == 2 then
- blueVotes += 1
- elseif T == 3 then
- otherVotes += 1
- end
- end)
- wait(10)
- if redVotes > blueVotes and redVotes > otherVotes then
- TextLabel.Text = "Player (@"..RedPlayer.Name..") won with "..redVotes.." votes!"
- RedPlayer:WaitForChild("leaderstats").Votes.Value += redVotes
- RedPlayer:WaitForChild("leaderstats").Wins.Value += 1
- elseif blueVotes > redVotes and blueVotes> otherVotes then
- TextLabel.Text = "Player (@"..BluePlayer.Name..") won with "..blueVotes.." votes!"
- BluePlayer:WaitForChild("leaderstats").Votes.Value += blueVotes
- BluePlayer:WaitForChild("leaderstats").Wins.Value += 1
- elseif otherVotes > redVotes and otherVotes > blueVotes then
- TextLabel.Text = "Player (@"..OtherPlayer.Name..") won with "..otherVotes.." votes!"
- OtherPlayer:WaitForChild("leaderstats").Votes.Value += otherVotes
- OtherPlayer:WaitForChild("leaderstats").Wins.Value += 1
- elseif redVotes == blueVotes and redVotes == otherVotes then
- TextLabel.Text = "It was a tie!"
- OtherPlayer:WaitForChild("leaderstats").Votes.Value += otherVotes
- BluePlayer:WaitForChild("leaderstats").Votes.Value += blueVotes
- RedPlayer:WaitForChild("leaderstats").Votes.Value += redVotes
- else
- TextLabel.Text = "No one voted."
- end
- task.wait(3)
- endGame(Player)
- task.wait(3)
- local TeamsUI
- for i,v in pairs(game.Players:GetPlayers()) do
- TeamsUI = v.PlayerGui:WaitForChild("TeamSelection")
- end
- Intermission(Player, TextUI,TeamsUI)
- return
- end
- function endGame(player: Player)
- local TextUI
- for i,v in pairs(game.Players:GetPlayers()) do
- game.ReplicatedStorage.UnmuteUser:FireAllClients()
- TextUI = v.PlayerGui:WaitForChild("TextUI")
- end
- local TeamsUI
- for i,v in pairs(game.Players:GetPlayers()) do
- TeamsUI = v.PlayerGui:WaitForChild("TeamSelection")
- end
- for i,v in pairs(game.Players:GetPlayers()) do
- v.PlayerGui:WaitForChild("VotingUI").VoteFrame.Visible = false
- end
- RedPlayer = nil
- BluePlayer = nil
- OtherPlayer = nil
- HigherThan4=false
- gameStarted = false
- RedTeamList = {}
- BlueTeamList = {}
- OtherTeamList = {}
- redVotes = 0
- blueVotes = 0
- otherVotes = 0
- if StartFunc ~= nil then
- StartFunc:Disconnect()
- StartFunc = nil
- else
- -- nothing
- end
- for i,v in pairs(game.Players:GetPlayers()) do
- v:LoadCharacter()
- end
- TeamsUI.Enabled = true
- end
- function Intermission(Player: Player, TextUI, TeamsUI)
- if StartFunc ~= nil then
- StartFunc:Disconnect()
- StartFunc = nil
- else
- wait()
- end
- RedPlayer = nil
- BluePlayer = nil
- OtherPlayer = nil
- HigherThan4=false
- gameStarted = false
- RedTeamList = {}
- BlueTeamList = {}
- OtherTeamList = {}
- redVotes = 0
- blueVotes = 0
- otherVotes = 0
- HigherThan4 = true
- print("Player added. "..Player.Name )
- while #game.Teams.Blue:GetPlayers() == 0 or #game.Teams.Other:GetPlayers() == 0 or #game.Teams.Red:GetPlayers() == 0 do
- wait()
- end
- for i, v in pairs(game.Players:GetPlayers()) do
- if v.Team == game.Teams.Red then
- table.insert(RedTeamList, v)
- elseif v.Team == game.Teams.Blue then
- table.insert(BlueTeamList, v)
- elseif v.Team == game.Teams.Other then
- table.insert(OtherTeamList, v)
- end
- end
- print(RedTeamList[1])
- print(BlueTeamList[1])
- print(OtherTeamList[1])
- --HigherThan4 = true
- TextUI:WaitForChild("TextLabel").Text = "Choosing a candidate for red team..."
- local PlayerRandomizer = game.Teams.Red:GetPlayers()[math.random(1, #RedTeamList)] -- Players:GetPlayers()
- task.wait(3)
- TeamsUI.Enabled = false
- RedPlayer = PlayerRandomizer
- TextUI:WaitForChild("TextLabel").Text = "Player: "..PlayerRandomizer.DisplayName.." (@"..PlayerRandomizer.Name..")"
- task.wait(2)
- TextUI:WaitForChild("TextLabel").Text = "Choosing a candidate for blue team..."
- local PlayerRandomizer2 = game.Teams.Blue:GetPlayers()[math.random(1, #BlueTeamList)]
- task.wait(3)
- BluePlayer = PlayerRandomizer2
- TextUI:WaitForChild("TextLabel").Text = "Player: "..PlayerRandomizer2.DisplayName.." (@"..PlayerRandomizer2.Name..")"
- task.wait(2)
- TextUI:WaitForChild("TextLabel").Text = "Choosing a candidate for other team..."
- local PlayerRandomizer3 = game.Teams.Other:GetPlayers()[math.random(1, #OtherTeamList)]
- task.wait(3)
- OtherPlayer = PlayerRandomizer3
- TextUI:WaitForChild("TextLabel").Text = "Player: "..PlayerRandomizer3.DisplayName.." (@"..PlayerRandomizer3.Name..")"
- task.wait(2)
- if RedPlayer ~= nil and BluePlayer ~=nil and OtherPlayer ~=nil then
- local SpeakingUI
- for i,v in pairs(game.Players:GetPlayers()) do
- SpeakingUI = v.PlayerGui:WaitForChild("Speaking")
- end
- SpeakingUI.Enabled = true
- local StartFunc = StartGame(Player, TextUI, SpeakingUI)
- else
- print("Something went wrong..")
- return
- end
- end
- Players.PlayerAdded:Connect(function(Player)
- PlayerCount.Value += 1
- local TextUI
- for i,v in pairs(game.Players:GetPlayers()) do
- TextUI = v.PlayerGui:WaitForChild("TextUI")
- end
- local TeamsUI
- for i,v in pairs(game.Players:GetPlayers()) do
- TeamsUI = v.PlayerGui:WaitForChild("TeamSelection")
- end
- Player.PlayerGui:WaitForChild("TextUI"):WaitForChild("TextLabel").Text = TextUI:WaitForChild("TextLabel").Text
- while PlayerCount.Value < 4 do
- wait()
- end
- while HigherThan4 do
- wait()
- end
- Intermission(Player, TextUI, TeamsUI)
- end)
- Players.PlayerRemoving:Connect(function(player)
- PlayerCount.Value -= 1
- local TextUI
- for i,v in pairs(game.Players:GetPlayers()) do
- TextUI = v.PlayerGui:WaitForChild("TextUI")
- end
- if player == RedPlayer or player == BluePlayer or player == OtherPlayer then
- print("Player removed. "..player.Name)
- TextUI:WaitForChild("TextLabel").Text = "One of the candidates left, restarting.."
- endGame(player)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement