I need help with this tree

I’m very new to learning code, and I’m just learning the basics. However, I have problems with the code and the output in the game.
So basically, I tried to make a tree, but I made a horrendous mess, there are some pictures below that show the tree in studio and the tree from the output:
Capture2 Studio tree

Output tree
The code is here:

local trunk = workspace.treeTrunk
local top = workspace.topOfTheTree
local foliage = workspace.biggestTreeFoliagePart -- this part is a model so maybe this helps?

trunk.BrickColor = BrickColor.new(20, 20, 3)
top.BrickColor = BrickColor.new(3, 20, 3)
foliage.BrickColor = BrickColor.new(3, 20, 3)
trunk.Anchored = true
top.Anchored = true
foliage.Anchored = true

If you have anymore question regarding this ask. Thanks for reading this!

Do Model Objects have an Anchored property? I don’t believe they do?

2 Likes

Put it suspended in the air. If it falls down something isn’t anchored.

I don’t think brickcolor.new is used for color3.new options.

If you want brickcolors you use strings, like “cocoa”, not numbers for the part colors. If you use Color3 you use a Color3, a number, which could be, for example, 20, 20, 3. Then again, I don’t know if this is what you planned, I just think it’s not what you want.

2 Likes

Do you make it a union or something because I only know the basics

Models don’t have an Anchored property. Use

for i,v in pairs(foliage:GetChildren()) do
   if v:IsA("BasePart") then
      v.Anchored = true
   end
end

edit: sorry for the formatting mistake, i’m new to the forum

It’s good I learnt pairs today or else I would be confused on that.

You missed an end

But yeah you can just loop through all the parts of the Model and check if they’re a Part or not:

for _, Part in pairs(foliage:GetChildren()) do
   if Part:IsA("BasePart") then
      Part.Anchored = true
   end
end

It still isn’t working, its collapsing to the ground in multiple different colourless (I’m British) parts. Should I just entirely scrap the model and make things to replace the void of the foliage?

Nah

Try implementing another check using GetDescendants maybe?

local trunk = workspace.treeTrunk
local top = workspace.topOfTheTree
local foliage = workspace.biggestTreeFoliagePart -- this part is a model so maybe this helps?

trunk.BrickColor = BrickColor.new(20, 20, 3)
top.BrickColor = BrickColor.new(3, 20, 3)
foliage.BrickColor = BrickColor.new(3, 20, 3)
trunk.Anchored = true
top.Anchored = true

for _, Part in pairs(foliage:GetDescendants()) do
    if Part:IsA("BasePart") then
        Part.Anchored = true
    end
end

You should also check your Output for any potential errors you could come across :wink:

1 Like

It doesn’t work… and the output has no errors about it. I’ll just go back to this idea :pensive::

Thanks for the help though! :happy1:

You don’t even need to use scripts for this. Just go in the model and make all the color for the parts what you want and also anchor them all. It is quite simple.

I recommend using Color3.fromRGB()

trunk.BrickColor = Color3.fromRGB(20, 20, 3)
top.BrickColor = Color3.fromRGB(3, 20, 3)
foliage.BrickColor = Color3.fromRGB(3, 20, 3) --I don't think models have a BrickColor property

Hmm, models don’t have a Anchored property.

If the model foliage has parts in it then I recommend using a in pairs loop
So you can modify all the parts inside the foliage model.

local foliage = workspace.biggestTreeFoliagePart:GetChildren()

for i,v in pairs do
v.Anchored = true
v.BrickColor = Color3.fromRGB(3, 20, 3)
print(i.."has been modified")
end

If it’s one part inside a model then use this script.
MAKE SURE TO PUT THE PART INSIDE OF biggestTreeFoliagePart IN THE WORKSPACE!

--Variables
local trunk = workspace.treeTrunk
local top = workspace.topOfTheTree
local foliage = workspace.part -- replace 'part' with whatever that was part inside of the 'biggestTreeFoliagePart' model.
--Script
trunk.BrickColor = Color3.fromRGB(20, 20, 3)
top.BrickColor = Color3.fromRGB(3, 20, 3)
foliage.BrickColor = Color3.fromRGB(3, 20, 3)

trunk.Anchored = true
top.Anchored = true
foliage.Anchored = true

Tell me if I got something wrong in the script, or if I misunderstood the “foliage”.

If you get any errors from the new script please make sure to send photos or just copy & paste them in your post.

Yeah guess you’re right, but he want’s to try what he learned since he’s new to scripting. (I think he does.)

Ah… Makes sense. Just some placeholder text to be able to send this