Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

For loop error help?

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

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

3 comments

0

I see, but now I am getting the error "BrickColor expected, got string instead"

0

Oh that's becaus eyou gotta write =BrickColor.new("Pastel brown") instead of just ="Pastel brown"

0

thx again bbe

This discussion is preserved as it was. New answers, comments, and votes are closed.