Cant change any checkpoints color

I am working on a checkpoint system and I don’t know how to check all the checkpoints and when they touch the checkpoint, no matter which check point it is, it will change color! Heres the code `local Checkpoints = game.Workspace.Checkpoints

game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new(“Folder”, plr)
leaderstats.Name = “leaderstats”
local Checkpoint = Instance.new(“IntValue”, leaderstats)
Checkpoint.Name = “Stage”
Checkpoint.Value = 1

plr.CharacterAdded:Connect(function(char)
	wait()
	if Checkpoint.Value > 1 then
		char:MoveTo(Checkpoints:FindFirstChild(Checkpoint.Value - 1).Position)
	end
	end)

end)

for i, v in pairs(Checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local Checkpoint = plr.leaderstats.Stage
if tonumber(v.Name) == Checkpoint.Value then
Checkpoint.Value += 1

		end
	end
end)

end end

Theirs a folder called Checkpoints and it has 1,2,3,etc

What exactly is the problem you are having, do they all change color when you touch one?

1 Like

I want it to change color but the problem is I only know how to do it one checkpoint at a time and instead have the script check which checkpoint is which and that checkpoint turns green etc

1 Like

Correctly formatted code:

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new(“Folder”, plr)
	leaderstats.Name = “leaderstats”
	local Checkpoint = Instance.new(“IntValue”, leaderstats)
	Checkpoint.Name = “Stage”
	Checkpoint.Value = 1

	plr.CharacterAdded:Connect(function(char)
		wait()
		if Checkpoint.Value > 1 then
			char:MoveTo(Checkpoints:FindFirstChild(Checkpoint.Value - 1).Position)
		end
	end)
end)

for i, v in pairs(Checkpoints:GetChildren()) do
	v.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild(“Humanoid”) then
		local char = hit.Parent
		local plr = game.Players:GetPlayerFromCharacter(char)
		local Checkpoint = plr.leaderstats.Stage
		if tonumber(v.Name) == Checkpoint.Value then
			Checkpoint.Value += 1

		end
	end
end)
end end

(I am confused as to why there are 2 extra end at the end)

1 Like

so for example, when the player rejoins all the past claimed checkpoints will turn green and if they claim one it turns green too??

if so you’d have to use a local script, to change the checkpoint’s color when they claim it + change the color of the past claimed checkpoints

(remote events can be used btw)

IDK how to do that lol I never really work with remote events and I want that to happen but I don’t know what to use for it. Like I did :GetChildren() is there something that is related to It that checks if all past checkpoints are green and when you claim on its green?

there isnt it just bugged out formatted code

1 Like

Used the folders index to solve it!

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