WARNING: This module is outdated. V2 of the module is planned and I further elaborate on it in the following reply, thanks.
---------------------------------------------------------------------------
Minimal, efficient and simple
TouchZone is a simple touch event wrapper for wide area player detection.
Delivers unnoticable performance delays while making your code much cleaner.
Handles all of the background work used to detect valid characters, and gives you easy-to-use events and methods to take advantage of.
Wide compability and open source
This module will work on any character that has a Humanoid under it, and it can run both on the server and the client, having minimal difference between the two.
Do bare in mind theres no security checks involved, so you might want to check the magnitude of newly added parts if you’re using the module server-side.
You’re free to edit and do anything with the module following the MIT license.
Saves your time and upgrades your touched events
My main goal with creating this module was to make setting up BasePart.Touched and BasePart.TouchEnded easier by offering a specific integration for characters, and making it extremely easy to detect character entering into your zones.
You can achieve the same behavior by listing all body parts that enter and leave, which fires the event when the first body part enters and last one leaves, this module just does that for you with some neat features.
Effortlessy create precise zones, with user handled filtering
This is not meant to be a replacement to BasePart.Touched for anything other than character detection in a large area, you’re discouraged from using it for any projectiles or rapidly moving areas due to innacuracy, though this is the case with the Touched event itself too.
Plug-and-play code sample for most users:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TouchZone = require(ReplicatedStorage:WaitForChild("TouchZone")) -- Require module
local MyPart = script.Parent -- Your part of choice
local ZoneFilter = function(character,part) -- Callback function for Touched (not required)
if part:FindFirstAncestorWhichIsA("Accessory") then -- Ancestor is an accessory
return false -- This part will be ignored
end
return true -- or this part will not be ignored
end
local MyZone = TouchZone.NewZone(MyPart,ZoneFilter) -- Attach a zone to the part with the filter
MyZone.OnEnter:Connect(function(character) -- Character starts touching the zone
print("Character entered zone!")
end)
MyZone.OnLeave:Connect(function(character) -- Character stops touching the zone
print("Character left zone!")
end)
In this sample I’m not allowing any accessories to be processed by the module, which is what most people would want to do, however you can filter it in any way you choose.
Read the API following the Github link for more information on everything the module can do.
You can add it to your game or look at the source code
Feel free to comment any suggestions or feedback, I’ll be actively checking this thread and updating the module with any reasonable requests and answering questions, thank you!