How would I be able to do this? (I don't really know how to explain it in words)

I’ve been stuck on something for around 2 hours and need a bit of help with it, I have a stage system but can’t figure out how to find out on the client which parts it should change the color of

(basically, I have a folder called Checkpoints, children are called Checkpoint0, Checkpoint1, etc. and I want to check if the checkpoint number is equal or lower than the stage leaderstat value, and if it is then it’d change the part color, on the client)

I’ve tried a lot of things but overall I can’t make any sense of this, and it’s probably terribly explained too. Any help would be appreciated.

1 Like
local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Leaderstats = Player.leaderstats
local Checkpoint = Leaderstats.Checkpoint
local Checkpoints = workspace.Checkpoints

local function update(id,part)
	if Checkpoint.Value <= id then
		part.Color = Color3.fromRGB(255,0,0)
	end
	if Checkpoint.Value >= id then
		part.Color = Color3.fromRGB(0,255,0)
	end	
end

for _,v in pairs(Checkpoints:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			local hum = hit.Parent:FindFirstChild("Humanoid")
			if hum and hit.Parent.Name == Player.Name then
				update()
			end
		end)
	end
end

Checkpoints.ChildAdded:Connect(function(child)
	update()
end)
1 Like

I don’t need it to run when it’s touched I only need it to do it once which is when the player joins the game as well as I don’t really think that would work

1 Like

wow your really making assumptions that something wont work before even testing it? but ok i can do player joining thats simple

1 Like
local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Leaderstats = Player.leaderstats
local Checkpoint = Leaderstats.Checkpoint
local Checkpoints = workspace.Checkpoints

local function update(id,part)
	if Checkpoint.Value <= id then
		part.Color = Color3.fromRGB(255,0,0)
	end
	if Checkpoint.Value >= id then
		part.Color = Color3.fromRGB(0,255,0)
	end	
end

while true do
for _,v in pairs(Checkpoints:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			local hum = hit.Parent:FindFirstChild("Humanoid")
			if hum and hit.Parent.Name == Player.Name then
				update()
			end
		end)
	end
end
task.wait(1)	
end
1 Like

Not really its mainly because why would you need it to be ChildAdded if all of the checkpoints are already in the folder

1 Like

idk maybe its self generating and it generates it everytime you get the checkpoint you didn’t specify but it should work

1 Like

it’s not

every checkpoint is already in the folder anyway and when the player joins I just want it to check at the start what their stage leaderstat is then change every checkpoint part color that is the stage before or the one that the player is on to another color

1 Like

ok so just remove it and use the part that isnt childadded you asked for help and you dont even test the script people give you

1 Like

Does it even make sense that you havent put anything in the () ?
I’m really questioning that right now

1 Like

Oh yeah sorry i forgot to put the arguments in there he should be able to figure that out himself though and hes probably reading these messages anyway

2 Likes
local folder = workspace:WaitForChild("Checkpoints")
local checkpoints = folder:GetChildren()
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local leaderstats = player:WaitForChild("leaderstats")
	local stageStat = leaderstats:WaitForChild("Stage")
	for i, v in pairs(checkpoints) do
		if v.Name == "Checkpoint"..stageStat.Value then
			v.Color = Color3.new(stageStat.Value/255, stageStat.Value/255, stageStat.Value/255)
		end
	end
end)

This will work providing there are fewer than 255 stages (notice the Color3.new() line).