Need Help Making An Axe That Can Destroy Objects In A Certain Amount Of Hits

Hey, I recently got the idea that I would add a feature into my game which is a feature where you can hit an object with a tool for a certain amount of times before it breaks. Any help is appreciated!

You could have a Hit value inside the script:

local Hits = 0 -- Declaring a hit variable

script.Parent.Activated:Connect(function()
     if Hits == 10 then -- We use 10 because that's how much times it could be used before it breaks
        print("Hits is 10, going to break tool!")
        script.Parent:Destroy()
   else
         Hits =+ 1
         -- Play your animation here 
    end
end) 

You would have to do the rest of the Play animation bit which isn’t too hard, but this is just a script on how it would work.

3 Likes

Personnaly i would use a IntValue added into the tool instead of a value inside the script. Players can modify the local script if they exploit. Which is not possible if you use a server script with a value

2 Likes

Why are you destroying axe? He want to make an axe that can destroy OBJECTS in a certain amount of hits, not itself.

1 Like

So what you can do is linking the axe and serverscript with a remote event. Add a IntValue into the axe and do all calculations through the server script

1 Like

You can use a touched event to destroy the object.

1 Like

of course he should use something to detecte what object he hits. But he want to do a script which allow you to destroy the item after a certain amount of hits

1 Like

Not gonna lie but I would use attributes instead of values because you don’t have to instance things plus it’s neater.

1 Like

Maybe you are right, i didn’t take a look at attributes

1 Like

I think the best thing to do is use a damage attribute.

1 Like

What I made hits an IntValue however where it says Hits =+ 1 the + is getting underlined in red.

Try += instead or Hits = Hits + 1

1 Like

And use .Value:

if Hits.Value ==
Hits.Value += 1
1 Like

Thanks. This is so much help for me and I’ll be sure to remember this anytime I come across it again.