im making a tree chopping system but im getting a problem where when you “swing the axe” it will just rapidly remove all of the tree “health” is there a way to make it so that every click removes only one
im using a remote event from the tool to a script in the tree
here is the tool code
local tool = script.Parent
local event = game:GetService("ReplicatedStorage")
local chop = event.Chop
local player = game.Players.LocalPlayer
tool.Activated:Connect(function()
chop:FireServer(player)
end)
here is the tree code
local tree = script.Parent
local hp = script.Parent.HP.Value
local event = game.ReplicatedStorage:WaitForChild("Chop")
local ghost = script.Parent.Ghost
local debouce = true
local cooldownTime = 2
event.OnServerEvent:Connect(function(player, humanoid)
tree.Touched:Connect(function(Obj)
local stat = player.leaderstats.OakWood.Value
debouce = false
wait()
if Obj.Name == ("Blade") then
hp = hp - 1
stat = stat + 1
print(hp)
wait(0.5)
if hp == 0 then
tree.Anchored = false
tree.Rotation = Vector3.new(-10, 0, 0)
wait(10)
tree.Anchored = true
tree.Position = ghost.Position
tree.Rotation = ghost.Rotation
hp = 3
end
end
wait(cooldownTime)
debouce = true
end)
end)