Alternatives to BasePart:Touched for tools?

Good morning,

I have been working with tools like swords and axes and found that using BasePart:Touched isn’t a good option since it either doesn’t fire in time of the touch or doesn’t fire at all.

Are there any alternatives to it? If so can you please link me the wiki page for it?

Thank you

use Raycast hitbox,

It’s nice.
Edit: Didn’t mean to quote lol, anyways i really recommend it.

I have tested it and I’m running into the same issue (which is not registering hits) but less often then the touched event.
Sadly the plugin isn’t perfect but if you know anything else please let me know

GetTouchingParts() is a good alternative.

https://developer.roblox.com/en-us/api-reference/function/BasePart/GetTouchingParts

“if the part itself has CanCollide set to false, then this function will return an empty table”

Tools usually have CanCollide set to false so players don’t go out-of-bounds. Are you sure this is gonna do the job?

There’s a hack to making GetTouchingParts work with parts that don’t have collision: connect a blank Touched event to the part without collisions. The note is paraphrased for the most part to be easy to understand for newer developers without using any weird tricks but GetTouchingParts actually relies on a TouchTransmitter instance.

Not ideal in all cases though - at that point you might as well be raycasting or using spatial queries. It’s the same as using a Touched event but instead you get all touching parts at the very moment you call GetTouchingParts in a table rather than handling colliding parts in an event-driven manner with Touched. Both fall under the same pipeline so if you want to get away from Touched then likewise you’re not really looking for GetTouchingParts either.

1 Like

Thank you for that.

But I don’t know how to use raycasting with tools. Can you link me a youtube tutorial or anything?

Thank you.

Intro to Raycasting on the Developer Hub. You can use this as a baseline template to understand what raycasting is and how to use the API. From there, you can look up other tutorials or try experimenting with them. There are resources and certain examples (such as Raycast Hitbox that was linked in pug64’s post) that can help you out as well.

2 Likes