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

I want to make a Tree Growing script that works, could anyone help me with this script?

Asked by 4 years ago
Edited 4 years ago

Hello, my current tree growing script (shown below) makes all the children of the Model (all of the tree's parts, like branches, etc) grow as well.

I have also made an inner part of the tree for decoration. I have succeeded at the growing bit so far, however, I have no idea how to make them scale/position correctly so that branches grow off the tree and not into it.
I have tried the Weld tool, but it doesn't seem to work. In other words, my problem is:

The branches grow into each other, and I only want them to grow off each other.
Here is a GIF of the issue

As you can probably see, it grows into a mess.

Here is my script (it is a child of the tree model):

local Max = 100 -- Max Size of tree
local Speed = 1 -- Speed of which it grows

while wait(Speed * 2) do
for name, TreePart in pairs(script.Parent:GetChildren()) do
    if TreePart:IsA("Part") then -- Checking if it's a part -- Finds tree Parts to make them grow
     print("Found "..TreePart.Name)

      if TreePart.Name == "Branch" or "InnerPart" then
    local Tree = TreePart
    local X = Tree.Size.X + (Speed/10)
    local Y = Tree.Size.Y + Speed       -- The amount tree grows
    local Z = Tree.Size.Z + (Speed/10)

    if Y < Max then      -- Grow tree if hasn't rached max size
    Tree.Size = Vector3.new(X,Y,Z)

    if TreePart.Name == "Branch" or "InnerPart" then
    local X2 = Tree.Position.X + (Speed/10)          -- ERROR IS HERE
    local Y2 = Tree.Position.Y + Speed/2         -- ERROR IS HERE
    local Z2 = Tree.Position.Z + (Speed/10)      -- ERROR IS HERE
    Tree.Position = Vector3.new(X2, Y2, Z2)  -- ERROR IS HERE

    else
    print("Not growing anymore")    

    end
    end
    end
    end
    end
end

Does anyone know how I could correctly position the branches? Thank you. ????

0
The tree grow in the middle of the "Part" because you get the position of the part(roblox let it in the middle of the part), so the tree alway spawn in one location c0nc3rt 61 — 4y
0
I'm not quite sure what you mean? IwanL17 5 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I have fixed it! I just had to make all of the Tree Parts into a Union. Had to edit the script a bit, but it works!

Ad

Answer this question