I don’t understand this code fully. To be more specific its this line game.Teams:FindFirstChild (checkpoint.Name).TeamColor I can’t wrap my head around what this line does and why I need it. I also want to know is checkpoint.Name getting “checkpoint” from the in pairs loop?
local checkpoints = game.Workspace:WaitForChild("Checkpoints"):GetChildren()
for i, checkpoint in pairs(checkpoints) do
checkpoint.TeamColor = game.Teams:FindFirstChild (checkpoint.Name).TeamColor
checkpoint.BrickColor = game.Teams:FindFirstChild (checkpoint.Name).TeamColor
end
I’ll comment on the code so it’s easier to understand.
--//Services
local Teams = game:GetService("Teams")
--//Variables
local CheckpointsFolder = workspace:WaitForChild("Checkpoints")
--//Loops
for i, checkpoint in ipairs(CheckpointsFolder:GetChildren()) do
--//The checkpoint variable references a child from CheckpointFolder. For example, it could be referencing CheckpointsFolder.Stage1
--//We must grab the checkpoint's name. For example; "Stage1"
local checkpointName = checkpoint.Name
--//We must grab the team that is related, by searching the Teams folder. For example; Teams.Stage1
local checkpointTeam = Teams:WaitForChild(checkpointName)
--//We must now set the correct TeamColor and BrickColor for the checkpoint
checkpoint.TeamColor = checkpointTeam.TeamColor
checkpoint.BrickColor = checkpointTeam.BrickColor
end