How can I make a Tree Chopping System?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a wood chopping system

  2. What is the issue? Include screenshots / videos if possible!
    Only the Trunk dissapears, and if I try to break with another tool (while having the axe in inventory) I can break with that tool also.
    – Also, the log doesn’t have any Clicking script.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I rewrote the script. Current script so far: (LOCATED IN STONE AXE TOOL)

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse() -- We need to get mouse (only in local script)
local Tool = script.Parent
local db = false
local log = game.ReplicatedStorage.Log

local character = player.Character
local Humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.Name = "Idle"
animation.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "7314295562"
local animtrack = Humanoid:LoadAnimation(animation)

Tool.Equipped:Connect(function()-- Runs function when you click while holding the tool
	Mouse.Button1Down:Connect(function()
		local Target = Mouse.Target -- Gets part that mouse is aiming at
		if Target then -- check if it exists
			if Target.Name == "Wood" then -- checks the name
				local Distance = (player.Character.HumanoidRootPart.Position-Target.Position).Magnitude 
				if Distance < 15 then -- Checks if plyer is close
					if db == false then
						db = true
						wait(1)
						log:Clone()
						log:Clone().Parent = player:WaitForChild("Backpack")
						log:Clone()
						log:Clone().Parent = player:WaitForChild("Backpack")
						Target.CanCollide = false						
						Target.Transparency = 1
						wait(6)
						Target.CanCollide = true
						Target.Transparency = 0
						db = false
					end
				end
			end
		end
	end)
end)


1 Like

Alright, so the problem with the breaking using a different tool is because instead of using axe.Activated you used mouse.Button1Down. This is fine but if you use the mouse you will have to check if it equipped, therefor, you can do two things to resolve this issue. 1 you can make a boolean that changes when you equip and unequip, so that when you click your mouse, if the bool reads false that mean it isn’t equipped and won’t break the log. Or 2, you can use axe.Activated to detect when you use the tool and then read the target to make sure it is wood.

Even though you made sure it was equipped before the mouse was clicked, this will not work because you can’t just turn a function off, therefor, once it is equipped, it will forever be useable with any tool.

ALSO I FEEL THE NEED TO SAY THIS: With all of this being done inside a local script, no one else will see this (Only the local player). Instead you need to call a remote event to a server script to break the block and insert it into your inventory / backpack.

ALSO, Instead of making the log that was broken completely transparent, you need to use Target:Destroy() . Reason being because even though it is completely transparent it will still be able to be a target. AGAIN, these changes have to be done on a server instead of a client!

TRY THIS AND SEE IF THIS WORKS:

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse() -- We need to get mouse (only in local script)
local Tool = script.Parent
local active = true
local log = game.ReplicatedStorage.Log

local character = player.Character
local Humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.Name = "Idle"
animation.Parent = script.Parent

animation.AnimationId = "rbxassetid://7314295562"
local animtrack = Humanoid:LoadAnimation(animation)


	Tool.Activated:Connect(function()
		local Target = Mouse.Target 
		if Target then -- check if it exists
			if Target.Name == "Wood" then -- checks the name
				local Distance = (player.Character.HumanoidRootPart.Position-Target.Position).Magnitude 
				if Distance < 15 then -- Checks if plyer is close
					if active == true then
						active = false
						log:Clone().Parent = player:FindFirstChild("Backpack")					
						Target:Destroy()
						active = true
					end
				end
			end
		end
	end)

``

Sorry for the late reply, I was sleeping. Problem is that the Wood doesn’t respawn

Oh lord! Instead of using Target:Destroy, I can make the parent of the target to ‘nil’ and then put it back to workspace!

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse() -- We need to get mouse (only in local script)
local Tool = script.Parent
local db = false
local log = game.ReplicatedStorage.Log

Tool.Activated:Connect(function()
	local Target = Mouse.Target 
	if Target then -- check if it exists
		if Target.Name == "Wood" then -- checks the name
			local Distance = (player.Character.HumanoidRootPart.Position-Target.Position).Magnitude 
			if Distance < 15 then -- Checks if plyer is close
				if db == false then
					db = true
					wait(1)
					log:Clone().Parent = player:FindFirstChild("Backpack")					
					Target.Parent = nil
					wait(6)
					Target.Parent = workspace
					db = false
				end
			end
		end
	end
end)

I still suggest remotes if this is a multiplayer game. Otherwise players will only see there own changes.