Why is my hitbox just not detecting touch events?

So basically im trying to make a projectile explode when hitting enemies, but the hitbox is just not detecting them, for context im using tween to move the projectile

https://gyazo.com/798caf4ff7fa427ae79404d54d9afae9 heres an example of the hitbox going right through the enemies and not detecting anything

here’s the part of my code that’s responsible for checking the touch event

local c
		c = lanza.Hitbox.Touched:Connect(function(hit)
			print(hit)
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= char then
				stop = true
				tween:Pause()	
				c:Disconnect()
			end
		end)

any help is welcome

1 Like

are there any errors in the output?
and make sure you have your client and server sides correct if your using both

As a tip you shouldn’t be using touched events for hitboxes. Since the detection rate is kinda bad, especially in a live game where there’s gonna be tons of lag alot of touches won’t register.

Use spatial queries instead, you can use getpartsboundsinbox for example. Or maybe raycasts.

2 Likes

looping getpartsinboundsbox wouldnt cause lag? since its moving

It’s probably this to be honest. What is char anyway?

I think that the touched event itself may actually be the problem, since touched events have bad detection. Especially when you have an object movijng super fast like in your video, thats why it probavly doesnt register.

I was going to assume that too, but I realised it may just be a local script or something and it may be for his own character.

the variable for the character thats launching the projectile

Eh, not that much. But, you don’t even need to loop. You can just use the hit detection when the player does the action. It’s like a click to shoot right? Just use an event.

You may need to use a temporary loop though actually.

1 Like

lemme try changing it to get parts in box

Besides it’s not like its detecting a huge amount of stuff anyway, it’s quite a small box from what I can see. So it probably wouldn’t be too heavy on performance.

Remove that check and see if it works. Also, check if you have the CanTouch property on.

Actually yeah I think thats the problem since in the video the box just goes straight through the enemies. But that might just be because its a big box and its moving fast.

.Touched runs every frame I think so in comparison the box isn’t moving that fast at all

didnt work, gonna try removing the “char” check, also the box has the variables for CanTouch enabled

worked to some extent, but now its exploding right when i launch it, because its detecting the thrower

Can you show us the section where you set the char variable?

image

the “plr” variable is the Player, i get it from a local script that detects tool activation, that sends a remote event to another script that only then calls this module

Not sure this will change much but try this:

local c
c = lanza.Hitbox.Touched:Connect(function(hit)
	local Character = hit.Parent
	local IsModel = Character:IsA("Model")
	local Hum = Character:FindFirstChildOfClass("Humanoid")

	if Character and IsModel and Hum and Character ~= char then
		stop = true
		tween:Pause()	
		c:Disconnect()
	end
end)

If this doesn’t work can you print char?