Raycast Hitbox 4.01: For all your melee needs!

Hi, trying to set up a blacklist and I receive the error: Argument 1 missing or nil
When I click to go to the code it appears to be complaining about ‘newHitBox’(see code below) which makes no sense:

local newHitbox = RaycastHitbox.new(Handle.Mesh)
newHitbox.RaycastParams = RaycastParams.new()
newHitbox.RaycastParams.FilterDescendantsInstances = Player
newHitbox.RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist

with out the Params setup the hitbox is created and works.

newHitbox.RaycastParams.FilterDescendantsInstances

Should be a table.

newHitbox.RaycastParams.FilterDescendantsInstances = { Player}

Hello, I need some help.

Is there a way for the hitbox to detect even if the attachments arent moving?
It appears the hitbox will only work if a part is moving…

I had the same problem last time.

if your way of detecting is

hitconnection.OnHit:Connect(function(hit, hum)
if hit.Parent:FindFirstChild("Humanoid") then
--code here
end
end)

Then you will experience delay

so you should change it to :

hitconnection.OnHit:Connect(function(hit, hum)
if hum then
--code here
end
end)

and check if it fixes your problem!
(also make sure that your hitbox module is client-sided)

No, it only works if you are moving. Raycasts requires distance for it to detect hits. The raycasts does not have a set width and therefore equals to zero distance if you are not moving.


Another developer here used the LinkAttachments function here to circumvent that issue since it allows hitboxes even while stationary.

1 Like

Good to know!
Thank you for the fast response too!

I have placed the hitbox code into my sword script and it is working ok, but is this a good practice? Should I have the definitions for the hit box in another script so it can be assigned as needed to different weapons and just set a call to the needed weapon script in the script that defines the hitbox?

There really isn’t a “proper” way to use this module. It’s designed to be as easy as possible to fit any project of all sizes. This is general advice but if its readable, convenient, and doesn’t hamper debugging, then it should be fine. Ultimately, as you develop your game further, you will learn yourself what is best practice for how to implement it according to your needs.

I had a quick question. Is there support or features that show the vector 3 point or any offset position relative to the parts hit? The reason I ask this is because I’m trying to detect the position one of the raycast attachments comes into contact with an object so I can put a visual effect at that point. Or even if there’s a way I can get the specific attachment, I can find the point using the world position.

OnHit returns the raycastresult which in turn provides you with the intersection position.

hitbox.OnHit:Connect(function(hit, humanoid, raycastResult)
     print(raycastResult.Position)
end)

This is amazing. The best way to solve hit detection. Thanks!

1 Like

I’ve got an issue with the module, the raycasts are not showing up correctly for me, here’s some code and a gif of what’s happening:

   local hitbox = Raycast.new(Character)
	

	hitbox.OnHit:Connect(function(hit, humanoid)
		if not hit:IsDescendantOf(Character) then
			print(hit.Name)
			humanoid:TakeDamage(Damage)
		end
	end)

	hitbox:HitStart(5)

https://gyazo.com/754aedc5e36f042938d2fa98df59448c

1 Like

Is this on the server? It looks like the server sees the weapon and animation at a different location than the client. See if the server is looking at a different position.

1 Like

The only thing on the client is a Remote Event doing :FireServer() inside of the ‘Punch’ tool script, the animation and the module are being used on the server.

1 Like

Since the server is handling this, you should check if the above is the case. Clients will see the animations play accordingly but the server may not have the proper animations replicated. The gif, from what I see, the animation plays on the server but the character does not have the “idle” animation which causes the rays to flatline at the end of the animation.

You should be able to see this by switching to the server view while testing in studio.

2 Likes

On the client, the tool is being held, however, the server doesn’t see the Punch tool being held, so on the server, the rays are accurate, but not on the client.

What should I do exactly?

Edit: Should I make an animation for holding the tool?

1 Like

Unfortunately, I don’t really have a lot of experience working with tools so it’s hard to come up with a definite solution. Honestly, I think it’s a Roblox bug that the default tool holding animation isn’t coming up on the server.


However, I can give some general insights on some techniques that may help. An idle animation may help since it doesn’t rely on the buggy tool to hold it for you. I would also make the client play the attack/idle animation. Load these animations on the humanoid’s animator, and it should replicate properly to the server with no issues.

Forcefully playing animations on the server, from what I’ve tested, always resulted in weird issues like you experienced.

2 Likes

Wow, thank you so much! I was looking for something like this for my game and this is so much more convenient than having to make it myself.

2 Likes

I have a sitation where a sphere shaped hitbox need to get bigger over time while it travels. Since the attachments will not also move as I tween the sphere, does anyone have any thoughts how this can be done?

It seems in cases like that that .GetTouching might be best, but i was hoping to stick with the raycasting.

1 Like

Can’t you pre-check the positions of the FINAL attachment positions when the ball is at its max size, And then tween the position of the attachments to the final position with the same time as the ball?

(Not WorldPosition)

EDIT: Actually… This won’t work, Since the attachments will spread more the bigger the ball gets, You could make a ton of attachments so they will all cover enough in the end, But that’ll be a lot of tweening to do…

1 Like