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!
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! :)