Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Error on 2nd Line of script to get team captains- Please help?

Here's the script:

local pes = game.Teams.PES:GetPlayers
local fifa = Teams.FIFA:GetPlayers


local myArray = {fifa, pes}
 
#myArray 
math.random(x) 
myArray[x] 

myArray[math.random(#myArray)]

end)

I'm basically trying to get team captains for a soccer game. The 2nd 'local' has an error for some reason and I can't seem to figure out why.

2 answers

✓ Accepted answer

wookey12's answer is incorrect. I'll show you the method to get a random player from each team here... this script chooses a random captain for each team

local PESmembers = game.Teams:WaitForChild("PES"):GetPlayers()
local FIFAmembers = game.Teams:WaitForChild("FIFA"):GetPlayers()

local PEScaptain = PESmembers[math.random(#PESmembers)]
local FIFAcaptain = FIFAmembers[math.random(#FIFAmembers)]

2 comments

0

Does this allow me to give the same random captain a gui/hopperbin?

0

Yes, the PEScaptian and FIFAcaptian are player instances, so you can just clone the GUI into PEScaptian.PlayerGui (or FIFAcaptian) and hopperbins into PEScaptian.Backpack

in the second variable (or local as you called it) you need to add "game" right before "Teams"

local pes = game.Teams.PES:GetPlayers
local fifa = game.Teams.FIFA:GetPlayers
local myArray = {fifa, pes}

1 comment

0

That didn't work, I appreciate your time, although!

This discussion is preserved as it was. New answers, comments, and votes are closed.