Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Not at all sure how to make color changing script for checkpoints?

Asked by 2 years ago

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

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
2 years ago

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
0
I already have a script to change the color when they're touched, I just need to check what stage the player is on when they join and make all the checkpoints behind them blue already. jraffey 1 — 2y
Ad

Answer this question