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.
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
Why are you destroying axe? He want to make an axe that can destroy OBJECTS in a certain amount of hits, not itself.
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
You can use a touched event to destroy the object.
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
Not gonna lie but I would use attributes instead of values because you don’t have to instance things plus it’s neater.
Maybe you are right, i didn’t take a look at attributes
I think the best thing to do is use a damage attribute.
I made hits an IntValue however where it says Hits =+ 1 the + is getting underlined in red.
Try += instead or Hits = Hits + 1
And use .Value:
if Hits.Value ==
Hits.Value += 1
Thanks. This is so much help for me and I’ll be sure to remember this anytime I come across it again.