I am planning on making a system where when you hit the tree with an axe, it disappears and you get wood. The script works for the most part, but the tree disappears after one hit.
Question: Is there any way that I could make it where you have to hit the tree with the axe multiple times?
The "Tree" model just has two parts called "Leaves" and "Trunk". I put a LocalScript in the axe tool. The script is listed below. Please let me know if you could help!
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local tool = script.Parent local active = true local animation = tool.Animation local wood = game.ReplicatedStorage.Resources.Wood tool.Activated:Connect(function() local char = tool.Parent local humanoid = char.Humanoid local AnimationTrack = humanoid:LoadAnimation(animation) AnimationTrack:Play() local target = mouse.Target if target then if target.Name == "Trunk" then local distance = (player.Character.HumanoidRootPart.Position-target.Position).Magnitude if distance < 2 then if active == true then active = false wood:Clone().Parent = player:FindFirstChild("Backpack") target.Transparency = 1 target.CanCollide = false target.Parent.Leaves.Transparency = 1 target.Parent.Leaves.CanCollide = false wait(5) target.Transparency = 0 target.CanCollide = true target.Parent.Leaves.Transparency = 0 target.Parent.Leaves.CanCollide = true active = true end end end end end)
just put in a variable call it hits then increment it every time the tree is hit and add an if statement checking if its equal to the hits that you want for it then inside put the code to destroy it