Hello!
How can I pick a random player from a team?
Script:
while true do
local Status = game.ReplicatedStorage:WaitForChild("Status")
local BCG = game.ReplicatedStorage:WaitForChild("BrickColorGui")
repeat
wait(0.01)
local playerTable = #game.Players:GetPlayers()
game.StarterGui.TalkGui.TalkFrame.TalkText.Text = "Waiting for 8 players... There are "..playerTable.." players in this server!"
until
playerTable >= 1
local playerTable = #game.Players:GetPlayers()
if playerTable >= 1 then
Status.Value = "Starting..." -- change the values to what you want it to say
wait(3)
Status.Value = "Welcome to Endurance v2!"
wait(4)
Status.Value = "This is a game based off the original Endurance game made by Endurance ©."
wait(4)
Status.Value = "The rules of playing this game are very simple."
wait(3.5)
Status.Value = "You have to choose your brick color, race on challenges, Random Players except winner will be picked. Fight to death."
wait(10)
Status.Value = "This process repeats until 2 players remain! They fight to death until they run out of bricks."
wait(8)
Status.Value = "You may choose your brick color."
wait(4)
BCG.Value = true
wait(10)
BCG.Value = false
Status.Value = "We may now start this round of Endurance v2, Good Luck!"
local interVal = 20
repeat wait(1)
interVal -= 1
Status.Value = "Intermission: "..interVal
until
interVal <= 0
local maps = game.Lighting.Maps:GetChildren()
local randomMap = maps[math.random(1, #maps)]
local map = randomMap:Clone()
map.Parent = workspace
wait(2)
local randomBlockWorth = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
local BlockWorth = randomBlockWorth[math.random(1, #randomBlockWorth)]
Status.Value = "This minigame is worth "..BlockWorth.." blocks!"
wait(4)
Status.Value = "This minigame we are playing today is..."
wait(4)
Status.Value = map.Name.."!"
game.ReplicatedStorage:WaitForChild("Minigame").Value = map.Name
wait(3)
Status.Value = "Good luck!"
wait(3)
local players = game.Players:GetPlayers()
for i,v in pairs(players) do -- teleport all the players inside the playing team since we removed all the ones who aren't in the playing team
if v:IsA("Player") then
if v.Team == game.Teams:WaitForChild("Playing") then
local Char = v.Character
v.Team = game.Teams.Alive
Char:PivotTo(map:WaitForChild("TeleportToMinigame").CFrame) -- put the spawn's CFrame between the pivotTo's brackets.
end
end
end
wait(3)
if game.ReplicatedStorage:WaitForChild("Minigame").Value == "Last to Leave Island" then
Status.Value = "Welcome to Last to Leave Island!"
wait(4)
Status.Value = "In this minigame, you have to fight on an island with your sword."
wait(6)
Status.Value = "Fight your opponent and the loser will be eliminated."
wait(5)
Status.Value = "The winner will have to fight the next winner."
wait(4)
Status.Value = "Earthworm Sally/Mayor of the Island will pick the random players."
wait(8)
Status.Value = "Good Luck!"
wait(4)
Status.Value = "Mayor: I am the great Mayor of this island!"
wait(5)
Status.Value = "Mayor: I choose to pick the following to fight..."
wait(5)
local playerTableforAliveTeam = #game.Teams.Alive:GetPlayers()
Status.Value = "Mayor: "..playerTableforAliveTeam[math.random(1, #playerTableforAliveTeam)].." VS..."
wait(5)
Status.Value = "Mayor: "..playerTableforAliveTeam[math.random(1, #playerTableforAliveTeam)].."!"
wait(5)
end
end
end
I need help. Thanks!