How to use TouchService - A wrapper for Touched connections

What is TouchedService?

TouchedService is basically a wrapper for your ‘Touched’ events that you may use from time-to-time. The primary function of TouchedService is to check that parts are actually touching whenever a Touched event gets called from a BasePart.

Why should YOU use TouchedService?

As we all may know, ‘hackers’ as I will call them, plague games on the ROBLOX platform from time to time. They’re a common threat and they become more of a threat to games as they increase in size. This is where TouchedService comes in, it is a wrapper for your Touched events, and by using TouchedService you can prevent ‘hackers’ from firing your Touched events from anywhere in the world, assuming you have no protection centered around your Touched events. The only way a ‘hacker’ or any player of that matter will be able to fire your Touched event, is while they’re touching that part.

  • Keep in mind: ‘hackers’ can circumvent this by teleporting to every part, but you also have to keep in mind this isn’t a full on anti-cheat, it’s simply raising the bar so it isn’t as ‘easy’ achieve this goal, and you have the ability to implement your own anti-cheat detection(s) if you wish to do so. This module will simply weed out newbies, and general scripts that exploit ROBLOX’s Touched functionality.

How to use TouchedService: Connections [Part 1/2]

TouchedService is a module that you require() in order to use, and from there you can practically start inserting all your objects that you want to be protected by TouchedService directly into the module by doing the following:

image

  • This code assumes that the module TouchedService is inside of a folder named ‘Modules’ inside replicated storage.

Result:

interactiveghostboy’s Place Number: 60 - Roblox Studio (gyazo.com)

Explanation:

The function addBasePart practically adds a Touched connection to the first object (BasePart) you pass through to the function, for example: TouchedService.addBasePart(PUT_BASE_PART_HERE). The second parameter, is the function you wish to run whenever that part is touched. It should look something like:

image

As seen in the code above.

How to use TouchedService: Disconnections [Part 2/2]

Now while you’re using TouchedService you should know that it also offers signal cleanup. It has a general cleanup which automatically runs whenever the part you’ve got connected is removed from workspace, and a custom cleanup called removeBasePart. removeBasePart can be implemented very similarly to addBasePart as seen below.

image

So now, we’re going to implement the disconnection inside of the code we made earlier, to connect our touched event to our part.

image

Result:

interactiveghostboy’s Place Number: 60 - Roblox Studio (gyazo.com)

Here’s the rbxm:

TouchedService.rbxm (1.8 KB)

Here’s the quick part of it because I posted on accident, I’ll fully update the post soon.

2 Likes

i realized how dumb this is, should get taken down sooner or later

1 Like

I would actually like to see something like this, as we all know touch events are super unreliable.

im probably going to make a re-post sooner or later but with distance checking based on ping possibly, because atm it uses GetPartsInPart() which is inefficient for server, so I might do distance checking for server and partsinpart for client, and the script will automatically tell which is which

1 Like

actually no

@Evolotionizing you can update your module to work better following the methods in the thread above.

It’s not dumb, you shouldn’t feel that way. I also thought of making something like this

2 Likes

Thanks! I’m going to look at your post and others under that thread, to further perfect TouchService. I appreciate you sending this to me, and I am now aware that this idea can be polished up a more then I originally thought- thank you.