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:
- 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:
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.
So now, we’re going to implement the disconnection inside of the code we made earlier, to connect our touched event to our part.
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.