Whats a good alternative for Touched events?

Hey I’m lastborn and I’m an intermediate scripter.
For a while now ive been using .Touched events but recently ive been told they arent accurate and are not good practice. What is a better alternative?

Also this is kind of random but could someone link me to a post explaining arguments & parameter.
Thanks everyone :slight_smile:

1 Like

Well, it’s kind of a cheat way to execute events. For example, if a player enters a certain room, instead of checking the player’s HRP position, they could just put a invisible part to execute the code

So a parameter is the Instance of a function’s event. For example, since you have been using .Touched events, the parameter of that event would be the object in the client that is touching the part or object. Parameters are very helpful when working with different types of specific objects because they narrow down the variable that is acting on the function’s event.

Sorry if I’m sounding a bit confusing but I hope I helped :slightly_smiling_face:

1 Like

Not too sure what you’re looking for tbh

THOUGH
Raycasts are decent for this
1, Accurate (I think lol)
2, Can’t be exploited

For .touched events exploiters can easily bypass it
Delete the part with that event boom bypassed

From what I know they can can’t delete/hook raycasts
This can also be useful for anti-noclip

I am no expert on raycasts but I believe you can keep one active without needing to spam create new ones
If you have some raycast knowledge, I suggest doing that

1 Like

look into using Region3’s on the server…
I have no further information as my friend uses them alot more than i do

1 Like

Always ask for proof when other people make claims a lot of people like to make claims without any evidence

this video might help explain about arguments & parameter

3 Likes

Thank you for the explanation, would using region3 instead be possible?

Interesting idea using raycast to detect the touching part instead, ill look into it but im not too sure about raycast. Do you think region3 would be viable?

From what ive heard touch events are bad practice, raycast are accurate but can sometimes be faulty and region3 are accurate.
Maybe im misinformed though?

Good idea, ill keep exploring options. Region3 or raycast sound possible?

Also thank you for the video link I will definitely watch the video:)

Hmm so would region3 or raycast be better?

Region3 is kind of doodoo. If used for something large-scale like Melee hitboxes for a game, it can really affect the game’s performance. Also, region3 does not support rotation but there are some modules that allow region3 to do so but it costs performance even more.
You should be using Raycast or Touched.
For raycast hitboxes:

Touched isn’t as bad as it seems. It is true that Touched is easily exploitable but you can add some extra checks on the server side. Say you are making a melee hitbox thing. It will be best performance vise for the client to tell the server where and what the client hit. Here, if the player is an exploiter and says that he totally hit a player from 5000 studs away you can just check the distance of the player from the hit part. If its within 5 studs or so you can execute the rest of the code else it wont. Simple right?

2 Likes

Thanks for the great explanation

1 Like

Because the player has network ownership of there character the player can tell the server where there position is so checking the position of a character to work out the distance is not safe and can be exploited so touch events ray casting and Region3 can all be exploited all the same

1 Like

So in the end just use touched events for small scale things but use raycasting for bigger things like melee?

if you have animations where your weapons move in such a way that they hit things I personally would use touch events

but if you don’t want to relay on animations to cover the attack range then you can use GetPartBoundsInRadius

you can read more about it here

this part here might be good to read

2 Likes