local player = game.Players.LocalPlayer
local CService = game:GetService(“CollectionService”)
player:WaitForChild(“leaderstats”)
local CheckpointsFolder = game.Workspace:FindFirstChild(“Checkpoints”)
local function updateCheckpointColors()
for _, part in ipairs(CheckpointsFolder:GetDescendants()) do
if part:IsA(“BasePart”) then
local stageNumber = tonumber(part.Name)
local parkourStages = game.Players.LocalPlayer.leaderstats:FindFirstChild(“ParkourStages”)
if stageNumber and parkourStages and parkourStages.Value >= stageNumber then
part.BrickColor = BrickColor.new(“Forest green”)
print(part.Name, stageNumber, parkourStages.Value, “Color changed to Forest green”)
else
print(part.Name, stageNumber, parkourStages.Value, “Color not changed”)
end
end
end
end
Try this, instead of using :FindFirstChild, use :WaitForChild for instances that are supposed to be there:
--//Services
local Players = game:GetService("Players")
local CService = game:GetService("CollectionService")
--//Variables
local player = Players.LocalPlayer
local parkourStages = player:WaitForChild("leaderstats"):WaitForChild("ParkourStages")
local CheckpointsFolder = workspace:WaitForChild("Checkpoints")
--//Functiions
local function updateCheckpointColors()
for i, descendant in ipairs(CheckpointsFolder:GetDescendants()) do
if descendant:IsA("BasePart") then
local stageNumber = tonumber(descendant.Name)
if stageNumber and parkourStages.Value >= stageNumber then
descendant.BrickColor = BrickColor.new("Forest green")
end
end
end
end
parkourStages.Changed:Connect(updateCheckpointColors)
updateCheckpointColors()