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

For loop error help?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

I feel like a complete noob, butttt this is erroring and I can't fix it

error: BrickColor is not a valid member of camera

Idk camera????

script.Parent.TrackTerrain.Value = _G.Terrains[math.random(1,#_G.Terrains)]
TrackPieces = game.Workspace:GetChildren("TrackPiece")
    if script.Parent.TrackTerrain.Value == "Desert" then
        for DesertConvert = 1, #TrackPieces do
            TrackPieces[DesertConvert].BrickColor = "Pastel brown"
            TrackPieces[DesertConvert].Material = "Sand"
        end
    end

1 answer

Log in to vote
1
Answered by
KoreanBBQ 301 Moderation Voter
8 years ago

Don't forget there aren't just BasePart objects in Workspace. Camera and Terrain are examples, you might have more if you put in scripts or whatever.

Those non-BasePart objects do not have BrickColors, thus giving you that error. Try putting aan if statement checking if the child is a BP.

Like that:

script.Parent.TrackTerrain.Value = _G.Terrains[math.random(1,#_G.Terrains)]
TrackPieces = game.Workspace:GetChildren("TrackPiece")
    if script.Parent.TrackTerrain.Value == "Desert" then
        for DesertConvert = 1, #TrackPieces do
        if TrackPieces[DesertConvert]:IsA("BasePart") then
              TrackPieces[DesertConvert].BrickColor = "Pastel brown"
               TrackPieces[DesertConvert].Material = "Sand"
        end
        end
    end

0
I see, but now I am getting the error "BrickColor expected, got string instead" NotSoNorm 777 — 8y
0
Oh that's becaus eyou gotta write =BrickColor.new("Pastel brown") instead of just ="Pastel brown" KoreanBBQ 301 — 8y
0
thx again bbe NotSoNorm 777 — 8y
Ad

Answer this question