I want to make it so that when I punch a tree log 5 times it will be destroyed, but it isn't working, here it is
local Log = script.Parent
Log.ClickDetector.MouseClick:connect(function() local Clicks = 0 Clicks = Clicks + 1
if Clicks == 5 then Log:Destroy() game.Workspace.Tree.Leaves.Anchored = false game.Workspace.Tree.Leaves.CanCollide = true wait(2) game.Workspace.Tree.Leaves.BrickColor = BrickColor.new ("Fawn brown") wait(3) game.Workspace.Tree.Leaves:Destroy() end
end)
Your function isn't working the way you want it to because you're setting Clicks to 0 each time your function is fired. In other words, you set Clicks to 0 inside of the function. So if you click that log, Clicks is always going to equal 1.
local log = script.Parent local clicks = 0 log.ClickDetector.MouseClick:connect(function() clicks == clicks+1 if clicks = 5 then --do whatever you want to do with your tree end end)
hope that helped
What you can do is add a value to the tree and set the script so that every time you punch it you add 1 to the value of the tree and once it hits 5 then set it to destroy the tree or leaves whatever you want Tree.Value = Tree.Value +1