Ive got an issue with my code

no i mean like put it inside the script where the trees generate so something like this

local tree = treeModel:Clone()
						
						local cd = tree:FindFirstChild("Click"):FindFirstChild("ClickDetector")
						
						if cd then
							cd.MouseClick:Connect(function()
								if tree then
									tree:Destroy()
								end
							end)
						end
						

						paintTreeLeaves(tree)

						tree:SetPrimaryPartCFrame(cf(posGrid[x][z])
							* cfAngles(0, noise(x/7, z/7, SEED * 2) * 10, 0)
							* cf(noise(x*5.4, z*5.4, SEED*2) * TREE_OFFSET, 0, noise(x*5.4, z*5.4, SEED*2) * TREE_OFFSET)
						)

						tree.Parent = workspace

						insert(instances, tree)

ok i fixed it

						local tree = treeModel:Clone()
						
						local cd = tree:FindFirstChild("Trunk"):FindFirstChild("ClickDetector")

						if cd then
							cd.MouseClick:Connect(function()
								if tree then
									tree:WaitForChild("Trunk"):Destroy()
									wait(10)
									tree:WaitForChild("Leaf"):Destroy()
								end
							end)
						end
						

						local cd = tree:FindFirstChild("Leaf"):FindFirstChild("ClickDetector")

						if cd then
							cd.MouseClick:Connect(function()
								if tree then
									tree:WaitForChild("Leaf"):Destroy()
								end
							end)
						end

I’m pretty sure your original code works, just WaitForCHild isn’t really working properly r now

while this is true, it’s better to use :Connect() because :connect() is depricated.