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

I want to use this alot however i dont understand it?

Asked by 5 years ago

Hey, I'm not quite sure if i'm allowed to post this here but. I'm having trouble understanding this script. You see I want to use more of this - but i have no clue what it does here is the script

` local teams do

teams = { }

local allTeams = game:GetService("Teams"):GetChildren()

for i = 1, #allTeams do

teams[allTeams[i].Name] = allTeams[i]

end

end`

Can anyone help?

0
It inserts all teams to a dictionary table. Amiaa16 3227 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Assign the variable "teams" to an empty array

teams = {}

Store all the instances inside of the Teams service into an array

local allTeams = game:GetService(“Teams”):GetChildren()

Loop through the indexes of the "allTeams" array. If there are five, the there are five indexes.

for i = 1, #allTeams do

Append a new team like a dictionary (key, element) into the teams array The key would be the teams name the element would be the contents inside the team, aka the players

teams[allTeams[i].Name] = allTeams[i]

tl;dr It re-formats the way of accessing the individual instances in each team Instead of doing:

game:GetService("Teams")["TeamName"]["Player"]

It is now done like:

teams["TeamName"]["Player"]

Personally it seems pretty useless since you can just do:

teams = game:GetService("Teams")
teams["TeamName"]["Player"]

and it would have the same effect. But that's only from a basic perspective, there may be other treats to this method that I cannot see at the moment.

0
Thank you but what does the allteams[i] bit do, why do you need [i] ? NinjaXDpro 22 — 5y
Ad

Answer this question