Hitbox Service, easily create Accurate Hitboxes using minimal scripting!

this module was really helpful! Thank you for making this

1 Like

Version 1.02, PRESET FUNCTIONS UPDATE!!!
Credit to: @geometricalC2123 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()

Actually, i think I may have forgotten to make start apply to .touched. Iā€™ll fix it soon.

1 Like

I tried to fix it somewhat, hereā€™s what I did:

local enteredConnection
	enteredConnection = RunService.Stepped:Connect(function() --- entered preset
		if self:GetState() == true then
		local NewHitbox = CreateWithPart:Create(Part, Overlap_Params)
		for i,v in pairs(NewHitbox) do
			if not table.find(OldHitbox, v) then
				EnteredEvent:Fire(v)
				end
	
			end
			OldHitbox = NewHitbox
		else
			enteredConnection:Disconnect()
			error("Cannot use the preset entered without starting a hit box. To start the hit box do: hitbox:Start()")	
		end
		

	end)
1 Like

I didnā€™t get notified, but i will say what someone said that has the same problem as me. (to the people saying that i should explain)
" Touched event is pretty stupid and has terrible hitboxes. "

1 Like

Hey, I am using the module and it seems like itā€™s not working.

local HitboxModule = require(game.ReplicatedStorage.HitboxModuleMain)
local Params = OverlapParams.new()
local Hitbox = HitboxModule:CreateWithPart(script.Parent, Params)
Hitbox:Start()
Hitbox.Touched:Connect(function(Object)
end)

For some reason itā€™s not detecting anything touching. No outputs or anything.

Seems you arenā€™t printing anything with the script you provided.

I have a full-on script inside for a tree chopping system.

> local HitboxModule = require(game.ReplicatedStorage.HitboxModuleMain)
> local Params = OverlapParams.new()
> local Hitbox = HitboxModule:CreateWithPart(script.Parent, Params)
> Hitbox:Start()
> local health = 15
> local bool = true
> local ongoing = true
> local respawn = math.random(15,20)
> Hitbox.Touched:Connect(function(Object)
> 	if Object.Name == "Handle" and Object.Parent:FindFirstChild("IsAAxe") and Object.Parent:FindFirstChild("Hit Sound") then
> 		local status = Object.Parent:WaitForChild("Type")
> 		local HitSound = Object.Parent:WaitForChild("HitSound")
> 		
> 		if health > 0 then
> 			if status.Value == 'Wood' then
> 				health = health - 1
> 				HitSound:Play()
> 			elseif status.Value == 'Stone' then
> 				health = health - 1.5
> 				HitSound:Play()
> 			elseif status.Value == 'Iron' then
> 				health = health - 3.5
> 				HitSound:Play()
> 			elseif status.Value == 'Diamond' then
> 				health = health - 5
> 				HitSound:Play()
> 			end
> 		elseif health <= 0 and bool == true then
> 			bool = false
> 			for i, x in pairs(script.Parent.Parent:GetChildren()) do
> 				x.Anchored = false
> 			end
> 			wait(respawn)
> 			
> 		end
> 	end
> end)

Well, i canā€™t help if you have the .touched function cut off

What do you mean cut off?
(30 limit)

Maybe its one of the if statements. Add a print(object) before the .touched and see what happens. Also for scripts click the <>
image

I wrote the post before u added the full script

It detects it being touched but doesnā€™t run the rest of the script. Im so stupid im so sorry. There was a value missing as it didnā€™t save when I quit.

Thens its at fault with the if statements.

1 Like

Also, this system is very neat! .Touched sometimes doesnā€™t work and it gets pretty annoying as its exploitable too.

1 Like

Iā€™d recommend to custom make it. I plan on revamping the module soon, since its not the best

Iā€™m not talking about your module if you think I am

1 Like