This is my first time posting on here so sorry if I do something wrong. So I made a feature when clicking on an object Its supports deleting parts of the object. Its works the first time but when it's cloned the function does not work anymore. I'm not sure what is going on.

The Local script for it is in the axe.

Here is the code.

local Tool = script.Parent 

local mouse = game.Players.LocalPlayer:GetMouse()

local Part = {};
table.insert(Part, workspace.tree1.tree.Wood);
table.insert(Part, workspace.tree1.tree.Wood2);
table.insert(Part, workspace.tree1.tree.Wood3);
table.insert(Part, workspace.tree1.tree.Wood4);
table.insert(Part, workspace.tree1.tree.Wood5);

local Part2 = {};
table.insert(Part2, workspace.tree1.Leaves);
table.insert(Part2, workspace.tree1.Leaves2);
table.insert(Part2, workspace.tree1.Leaves3);
table.insert(Part2, workspace.tree1.Leaves4);
table.insert(Part2, workspace.tree1.Leaves5);
table.insert(Part2, workspace.tree1.Leaves6);
table.insert(Part2, workspace.tree1.Leaves7);
table.insert(Part2, workspace.tree1.Leaves8);
table.insert(Part2, workspace.tree1.Leaves9);
table.insert(Part2, workspace.tree1.Leaves10);

local hits = 0
local max_hits = 5
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local chop_sound = game.ReplicatedStorage.ShopItems.Axe_1.Chop2
local SpareTree = game.ReplicatedStorage.tree1
Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
	if mouse.Target:FindFirstChild("Clickable") then
		print("You did it") --Testing
		hits = hits + 1
		chop_sound:play()

		if hits >= max_hits then
			for _, obj in ipairs(Part2) do obj:Destroy(); end; --This is the code That I am talking about.
			if hits >= max_hits + 1  then
				player.leaderstats.Wood.Value = player.leaderstats.Wood.Value + 1
				for _, obj in ipairs(Part) do obj:Destroy(); end; --This is the code That I am talking about.
				wait(3)
				local NewTree = SpareTree:Clone()
				NewTree.Parent = workspace
				print("Replanted") --Testing
				hits = 0
			end 
		end
	end
end)

end)

1 comment

0

Is there any errors in output?