Trying to make a checkpoint system to make the colors change after player already passed the checkpoint

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

updateCheckpointColors()

player.leaderstats:FindFirstChild(“ParkourStages”).Changed:Connect(updateCheckpointColors)

the script above is not working, and shows no errors

Where is this script located? Could you also show the explorer of the CheckpointsFolder?

the only thing that I need help with now is like saving the parts to turn green everytime the player joins all the parts are green already.

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()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.