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

Can someone help me with this treeing script?

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

✓ Accepted answer

First of all there is some code that is not serving any purpose here...You were missing a then on your elseif and 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)

1 comment

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.

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