Hitbox Service, easily create Accurate Hitboxes using minimal scripting!

What’s wrong with .Touched? :thinking:

(Except for the fact it’s a bit more exploitable)

1 Like

You should probably explain why .Touched event is bad.

2 Likes

Zones+ was released a ton of time ago too and it’s really great. Can’t find a link to it but if you search for Zones+ you should be able to find it

1 Like

If you connect a touched event to a small object which is fast the hitbox will become innacurate resulting in tunneling (passing thru objects and touched event not firing)

3 Likes

Idk metatables since I’m so trash at them but

module.__index = module
setmetatable({}, module)

What’s this for???

Also, one question, how do I connect it to a part generally?

:CreateWithBox???

2 Likes

You should probably use OverlapParams instead of Region3, as they’re the replacement for Region3 which is deprecated. Unless you are, the source code in the post doesnt look like the full code, but the title says Region3.

It uses overlap params. Not region 3. I just call it that.

1 Like

Both have different uses. Hitbox service can both be used for hitboxes and zones. Zone+’s main use is for zones. Hitbox service in my opinion has more flexibility. Tho I never used zone+ some im not sure.

Can you explain what you mean here?

I meant what hitboxtype should I use to connect to a part.

I’d recommend using :CreateWithPart. Since it connects to the specified part.

Ok but does it create a part or just makes the hitbox?

It makes the hitbox. Just make sure to put the part and it’ll calculate the hitbox automatically where the part is.

1 Like

It’s simple. Its to remove the default setting from the self function. If you try to print self, it’ll say a “function” which is there by default. So thats just used to clear the table so its less messy.

1 Like

Version 1.01, State Updates

Hello! This is the module’s FIRST ever update! This update now allows you to stop hitboxes and allows you to get the state of a hitbox!

How to use:

How to Use

First of all, if you DONT know how to use this module then PLEASE look at the how to set up part of the first post.

The :Stop function allows you to stop a hitbox from going on. This is useful for when you want to stop hitboxes. To use this you must call the :Start function of a hitbox first, then stop it.

local HitboxModule = require(game.ReplicatedStorage.HitboxModuleMain)
local HitBox = HitboxModule:CreateWithRange(script.Parent, script.Parent.Position, 10, OverlapParams.new())
HitBox:Start() -- starts the hitbox
wait(3)
HitBox:Stop() -- stop the hitbox after 3 seconds

Next, the :GetState() function. This function will get weather or not the hitbox has started. True means it has, false means it hasn’t. This is useful for either wanting to see if a hit box is on going. Or preventing errors when stopping a hitbox. Here’s an example of a good time to use the :GetState function. Lets say you have a re-calculating hitbox. But then you stop it. Well, theres a good chance that it may error with the error message of: Cannot get items when hitbox hasn’t started. To start do: hitbox:Start(). This is an issue. In order to fix this we’ll need to use the :GetState Function.
Script:

local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
	
	local HitboxModule = require(game.ReplicatedStorage.HitboxModuleMain)
	local HitBox = HitboxModule:CreateWithRange(script.Parent, script.Parent.Position, 10, OverlapParams.new())
	HitBox:Start() -- starts the hitbox
	if HitBox:GetState() == true then -- checks state
	local Items = HitBox:GetItems()
	
	wait(1)
		HitBox:Stop() -- stops state
		end
end)



this module was really helpful! Thank you for making this

1 Like

Version 1.02, PRESET FUNCTIONS UPDATE!!!
Credit to: @regexman for making this update possible. He wrote the prototypes for these functions which helped release this update WAY faster! I simply made it slightly better and compatible with all hitbox methods

Hello! Today, I’m going to be introducing 2 new functions to ALL hitbox methods, PRESET Functions. You can now use these in order to detect when something is entering, or touching the hitbox. These presets are: Entered and Touched. Keep in mind that I’ll be adding more presets as time goes on!
Also, it’s recommended that you use the .Entered and .Touched for future work. As the :GetItems function is no longer the number 1 priority and because :GetItems is worse than using these presets.
How to Use:

How to use

First, i’m going to assume you know how to use this module, if you dont, look at the first post.

Entered:
The entered preset fires every time an object enters the hitbox. This event is good for things that are meant to happen once. If you want things to happen multiple times when something is in the hitbox, refer to using Entered’s twin: Touched. Every time the entered preset is called, it’ll have one argument, the object that entered the hitbox. Knowing this, we can make a script that does something every time you enter the hitbox. Keep in mind, you can use this on ANY method and make it do ANYTHING you want!

local HitboxModule = require(game.ReplicatedStorage.HitboxModuleMain)
local Hitbox = HitboxModule:CreateWithPart(script.Parent, OverlapParams.new())
Hitbox:Start() -- starts the hitbox, otherwise it'll error
Hitbox.Entered:Connect(function(Object) -- the object argument is the object that entered the hitbox
	print(Object.Name) -- prints the object's name
end)

Touched:
Touched is pretty much BasePart.Touched. Except 100X better. It has BARELY any server delay and isn’t exploitable. This is a repeating Preset. Which means it’ll repeat forever. If you want something that making something happen once when something goes into the hitbox, then use .Touched’s twin, .Entered. More info above. For this event, i’ll recommend that you :CreateWithBox. As :CreateWithPart may not detect things above of the hitbox(This only applies to solo parts, not players. Only use :CreateWithPart with the .Touched preset if your part has collisions off, otherwise use :CreateWithBox). Keep in mind, you can use ANY method and make it do ANYTHING you want! So lets get into it!

local RegionStats = Region3.new(script.Parent.Position - script.Parent.Size/2, script.Parent.Position + script.Parent.Size /2) -- gets the part's dimensions
local HitboxModule = require(game.ReplicatedStorage.HitboxModuleMain) -- requires the module.
local Hitbox = HitboxModule:CreateWithBox(script.Parent,RegionStats.CFrame, RegionStats.Size, OverlapParams.new()) -- makes hitbox
Hitbox.Touched:Connect(function(Object) -- this object that the hitbox touched.
print(Object)
end)

Also, the hitbox.Touched preset will still detect you touched even if you jumped on the part. Making it really hard to impossible to exploit it.

If you find any bugs, or have suggestions for future updates/presets then feel free to say below!

2 Likes

fyi… with the new update you can now do hitbox.Touched. Which means you can have better .touched events using the module!

1 Like

noice

1 Like

One question, does Hitbox:Stop() and Hitbox:Start() apply to the .Touched event?

It seems to keep going after I have called Hitbox:Stop()