How to detect if a tool is activated (swinging) while hitting

Hi, I have an object that is meant to break when a specific team swings at it, however it takes damage just by coming into contact with a weapon, how can i refine this to only take damage when a weapon swing is taking place? I tried this line but knew it probably wouldnt work:

if hit.Parent:IsA("Tool") and hit.Parent.Activated then

(video attached below)
thanks!

1 Like

You could handle it within the tool instead of the block.

The tool detects mousebutton1down, and fires a remoteevent to the block.

Within the blocks script, detect if the tools handle is touching it (IsTouching)

I could do that, however the weapon script I use is a ServerScript, so bindable events would have to be used (if im not mistaken for Server-Server communication). Would you still say its a viable method (I haven’t used BindableEvents at all so not sure of their performance usage)

My way of understanding it was to do a check the name of the object the knife hits when it connects the Touched event, and if its the barricade name fire a bindable event, is that what you were more or less thinking?

Edit: Im already seeming to have a few issues with this method, could it not be done by checking the velocity of the tool hitting it? (As id imagine the velocity of the weapon would be 0 if you are just statically running around with it, but wouldn’t be the case if a weapon animation is playing?)

If you have a swing animation, you can use animationTrack.Stopped:wait(). If not, then you can add a debounce.

debounce = true

if debounce then
debounce = false
event
wait(3)
event:disconnect()
debounce = true
end

Could I use a check of IsPlaying on the tool to check if an animation is playing? As this would make sense to me that it should work

Edit: Wouldn’t be completely sure on how to detect the animation though

You can have the player change a boolean instance value or attribute.

1 Like

I could also create a BoolValue in the Tool, right?

Yes, no need to ask, don’t be afraid to try anything.

Haha apologies its just my way of responding, I know it should work the same, working on adding it in now and il get back to you.

Well this is a tricky question. you could use a local variable that only activates once the sword gets activated and if it hits the part then it would destroy. but it’s not really the best. I don’t think there’s really any feature of doing this else way or at least I’m not aware of one.

1 Like

This method works well, went with putting a BoolValue in the knife. Thanks a lot!