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

Can someone help me with this treeing script?

Asked by 10 years ago

This kind of tree isn't the one with leaves and a stem, but a hierarchy of parent and child instances. I used a for loop to find what was in my designated point...

for _, v in pairs(game.Workspace:GetChildren()) do
    if v:IsA("Part") then
        print("Part found")
    end
end

At that point I realized "Hey, I could make something that searches models!". My goal of that was to do the above script, but if it found a model start the process again but have that model as the search point.

local a = game.Workspace
local b

function Tree(location)
    loc = location:GetChildren()
    for _, v in pairs(loc) do
    if v:IsA("Part") then
        print("Part found")
    elseif v:IsA("Model")
        b = v
        Tree(b)
    end
end

for _, v in pairs(a:GetChildren()) do
    if v:IsA("Part") then
        print("Part found")
    elseif v:IsA("Model")
        b = v
        Tree(b)
    end
end

What happens there is the process stops when it hits the model rather than seeing what's inside.

1 answer

Log in to vote
1
Answered by 10 years ago

First of all there is some code that is not serving any purpose here...You were missing a thenon your elseifand you were missing an end.

function Tree(location)
    loc = location:GetChildren()
    for _, v in pairs(loc) do
        if v:IsA("Part") then
            print("Part found")
        elseif v:IsA("Model") then --Missing  then
            Tree(v)
        end
    end --Missing end.
end

Tree(Workspace)

0
I did forget that, didn't I? Wow, never realized that. I managed to burn myself out on this and couldn't see this simple answer. Thanks, notsopwnedg. XanthicDragon 38 — 10y
Ad

Answer this question