Ok so basically I'm making an obby and I have a script that makes the checkpoints change color once they are touched. To expand on this, I'm trying to make a script that checks the player's stage value and if the stage value is higher than the value of a checkpoint, then the color of the checkpoints up to that stage will already be that color. This is written in a local script. I'm extremely new to scripting and I'm sure tons of things in this script are wrong but I really would like some feedback. I would also like to add that I plan on making it so that you can reset your stage and when that happens, I need the checkpoints to return to the original color, so I would like for any solution to be compatible with that as well. Thank you.
local stageHolder = game.Workspace.Stages local stages = stageHolder:GetChildren() local blue = table.getn(stages) local player = script.Parent.Parent local stageValue = player.leaderstats.Stage.Value for i,v in pairs(stages) do local text = i local number = v while true do if v >= stageValue then stageHolder[v].Color = Color3.fromRGB(71, 255, 243) wait(0.1) end end end
Here you go
for _, checkpoint in pairs(workspace:FindFirstChild("Checkpoints"):GetChildren()) do if checkpoint then checkpoint.Touched:Connect(function(hit) if hit and hit.Parent:FindFirstChild("Humanoid") and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) and not checkpoint:FindFirstChild("HasTouched") then checkpoint.BrickColor = BrickColor.Random() local hasTouched = Instance.new("BoolValue") hasTouched.Name = "HasTouched" hasTouched.Value = true hasTouched.Parent = checkpoint end end) end end