Raycast Hitbox 4.01: For all your melee needs!

Debug toggle seems to not work?
https://gyazo.com/31891be42c6f3f04d95b702c2e4864b9

My code:

local HitboxMod = require(game.ReplicatedStorage.Modules.RaycastHitbox)

local Debug = false

script.Parent.TextButton.MouseButton1Click:Connect(function()
	if Debug == false then
		Debug = true
		script.Parent.TextButton.Text = "Debug: On"
		HitboxMod:DebugMode(true)
		
	elseif Debug == true then
		Debug = false
		script.Parent.TextButton.Text = "Debug: Off"
		HitboxMod:DebugMode(false)
	end
end)
1 Like

DebugMode has been changed since 2.0. The new variant is initializing a hitbox first and then calling DebugMode on that. This ensures that you can turn on/off debug rays for specific hitboxes instead of universally enabling it on all of them.

local HitboxMod = require(game.ReplicatedStorage.Modules.RaycastHitbox)
local MY_HITBOX = HitboxMod:Initialize(SwordExample, {Character})

local Debug = false

script.Parent.TextButton.MouseButton1Click:Connect(function()
	if Debug == false then
		Debug = true
		script.Parent.TextButton.Text = "Debug: On"
		MY_HITBOX:DebugMode(true)
		
	elseif Debug == true then
		Debug = false
		script.Parent.TextButton.Text = "Debug: Off"
		MY_HITBOX:DebugMode(false)
	end
end)

However, if you are still using V1.0+, it should still work the way you are doing.

1 Like

Oh, I see, Sorry for that!
(30chars)

1 Like

If i wanted to make a fist tool, What would be the best method to getting the attachments into the arms?

Also, Is it possible to have both humanoid and part detection?

1 Like

The lazy approach could be to weld invisible proxy parts to the characterā€™s hands and the attachments would be in those parts. If you want to use the raw limbs of the character to set up raycast points, youā€™ll need to do a bit of heavy lifting by instancing them where you want them and destroying them later when they are no longer needed.

Raycasting is only for parts so it canā€™t detect Humanoids. The module should take care of this for you automatically though by passing both the part(s) it came into contact with as well as the Humanoid itself.

1 Like

I see, Thank you for the response!

1 Like

Thatā€™s epic m8, good job. But ig its still need more optimization. Btw i have problem when hitbox wont show up but i did everything correctly ig.

1 Like

You should provide more details so that the OP is able to understand what exactly you mean: vague responses usually arenā€™t helpful. Why are you suggesting that it could use better optimisation and how are your hitboxes not working? Are you able to show a screenshot of your model or otherwise?

I havenā€™t had much optimisation issues while using this myself.

1 Like


they located at arms

1 Like


why it wont work right?

2 Likes

I had the same problem when i was making stands, For some players the attachments move correctly, But for me they stayed in place like your gif is showing, Iā€™m not quite sure why.

1 Like

I have looked at a similar stand problem and it seems to be a roblox problem. If the stand is created serversided, parented to player or has physic ownership to the player, and this module is being ran serversided, it exhibits the problems you are seeing.

If you are testing in roblox studio, switch over to the server view from client, the stand will actually have its animations not replicated correctly. There is no easy fix other than to make stand entirely clientsided or making the stands physic ownership server. The attachment positions unaligned are not the module fault.

1 Like

Hey for some reason whenever I call on the Deinitialize method it returns nil. Both the HitBox and the Weapon exist, so Iā€™m not sure whatā€™s causing the issue here.

Code:

if character:FindFirstChild('Weapon') and HitBox then
    HitBox:Deinitialize(character.Weapon);
    return true;
end
return false;

Hereā€™s the error:
image

1 Like

It should be RaycastModule:Deinitialize, not the hitbox itself.

2 Likes

Yeah, itā€™s still throwing up a bunch of errors, this time in the module itself. If I donā€™t deinitialize it, will the module itself deinitialize if I remove the object itself? Cos if so I wonā€™t need to worry about manually deinitializing it.

1 Like
  1. It would be helpful if you stated what errors showed up in the module. As far as I know, it works for me.

  2. Deleting the actual instance that you initialized with should auto clean up the hitbox, though this is a very expensive operation if you are doing it constantly.

1 Like

Those are the errors itā€™s giving me. My code is the same as before except Iā€™ve switched it to use RaycastModule:Deinitialize(Object). It happens whether I call it before destroying the object, or if I call it without destroying the object.

1 Like

Hmm, did you deinitialize it already? The output message ā€˜hitbox object awaiting deletionā€™ suggests it is on its way to be garbage collected and no longer usable. The only thing I can probably think of is you deinitialized already but tried deinitializing again when the instance was nil.

1 Like

Any idea why, despite the fact that I have two character models in the exact same position, they donā€™t get hit at the same time? Currently Iā€™m only running HitStart() and nothing else. One player gets hit, the rays seem to ignore the second player for a few moments, and then the second player gets hit. Is there a solution to this?

1 Like

Do you have a video of the problem? If the rays are already inside a target, it will not register it (rays only register hits going inside a part, but canā€™t register a hit if the rays are coming out of the part). I advise developers to implement their hit detection on the client side to prevent any weird server delays as well.

1 Like