Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I need help making it so that in 5 clicks a part is destroyed?

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)

2 answers

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

This discussion is preserved as it was. New answers, comments, and votes are closed.