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.
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)
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
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
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
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
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).