I’m working on a script that generates a tree similar to lumber tycoon 2. The issue I am running into is when I attempt to call the function to create a new branch after passing the parent branch, I get the error: “attempt to call a nil value”
Snippet:
while(wait(growthRate))do
for i, branch in pairs(branchGrowthXZ) do
if table.find(branchGrowthY, branch) then
if branch.Size.Y >= templateTreeData.maxLength then
--function that outputs the error:
newBranch(branch)
local branchIndex = table.find(branchGrowthY, branch)
print(branch)
table.remove(branchGrowthY, branchIndex)
else
branch.Size = branch.Size + Vector3.new(0, 0.1, 0)
branch.CFrame = branch.CFrame:ToWorldSpace(CFrame.new(0, 0.05, 0))
end
end
branch.Size = branch.Size + Vector3.new(0.01, 0, 0.01)
end
end
I’ve tried moving around the table.remove function, and when priting the value everything is outputed just fine: