Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make a team captain selecting script function at the start of a game?

Asked by 7 years ago

I'm trying to have this script start up as soon as 4 players join the server:

wait(10) local PESmembers = game.Teams:WaitForChild("PES"):GetPlayers() local FIFAmembers = game.Teams:WaitForChild("FIFA"):GetPlayers() local tool = game.ReplicatedStorage.CrestSelection

local PEScaptain = PESmembers[math.random(#PESmembers)] wait(1) print(PEScaptain.Name "has been selected as the PES captain!!") local FIFAcaptain = FIFAmembers[math.random(#FIFAmembers)] wait(1) print(PEScaptain.Name "has been selected as the FIFA captain!!")

game.ReplicatedStorage["Select"]:Clone().Parent = game.Players["PEScaptain"].PlayerGui wait(30) game.ReplicatedStorage["Select"]:Clone().Parent = game.Players["FIFAcaptain"].PlayerGui end end

Thank you for your time in advance!

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You can use game.Players.NumPlayers to find the number of players in the game, or use #game.Players:GetPlayers() Check for four players and then start the script.

repeat wait() until game.Players.NumPlayers >= 4 -- Here is the code I added to check for four players.

wait(10) 
local PESmembers = game.Teams:WaitForChild("PES"):GetPlayers() 
local FIFAmembers = game.Teams:WaitForChild("FIFA"):GetPlayers() 
local tool = game.ReplicatedStorage.CrestSelection

local PEScaptain = PESmembers[math.random(#PESmembers)] 
wait(1) 
print(PEScaptain.Name.." has been selected as the PES captain!!") 

local FIFAcaptain = FIFAmembers[math.random(#FIFAmembers)] 
wait(1) 
print(PEScaptain.Name.." has been selected as the FIFA captain!!")

game.ReplicatedStorage["Select"]:Clone().Parent = PEScaptian.PlayerGui 
wait(30) 
game.ReplicatedStorage["Select"]:Clone().Parent = FIFAcaptian.PlayerGui 

Accept the answer and upvote it if I helped! :)

0
Thanks! I don't have enough reputation to upvote though, sadly. comotose 3 — 7y
Ad

Answer this question