Raycast Hitbox 4.01: For all your melee needs!

You would use this like you would normally create a sword with this module. Depending on the rig you are using, you’d want to either put DmgPoint attachments in the hands or arms of the player and then follow the github tutorial. You could probably search this specific thread, like keywords ‘fist’, ‘punch’, or ‘melee’. There are a lot examples from people who needs help similar to yours and I think you may find it helpful. Though if you have any questions that are unanswered in those, I’ll be more than happy to help.

oh i see, thank you very much!

Hello! Do you think it would be possible to add built in support for filters? For example make it so only parts with a specific CollectionService tag can be detected, or specific collisiongroups.

thanks

Refer to this post for CollisionGroups

You can also use GetTagged in place of the ignore list if you are using CollectionService.

local newHitbox = RaycastModule:Initialize(object, CollectionService:GetTagged("MyTag"))

Thank you for the quick response!
I had already modified it to do such. I was more so requesting a future built in option when initialising it. (Since i also need to blacklist some objects that may have the tag, its a bit more than just using gettagged.)

I’m getting this error: ReplicatedStorage.RaycastHitboxV3.Tools.Signal:15: invalid argument #1 to ‘create’ (function expected, got nil). You previously said that it is likely due to a typo but I’m not sure if that’s the case for me.

Here’s the code (Local script parented to starterplayerscripts)

local RAYCAST_HITBOX = require(RS.RaycastHitboxV3) 
local LeftGripAttachment = Player.Character:FindFirstChild("LeftPunch"):FindFirstChild("Handle"):FindFirstChild("LeftGripAttachment")
local RightGripAttachment = Player.Character:FindFirstChild("RightPunch"):FindFirstChild("Handle"):FindFirstChild("RightGripAttachment")
LeftGripAttachment.Name = "DmgPoint"
RightGripAttachment.Name = "DmgPoint"
local newHitbox = RAYCAST_HITBOX:Initialize(Player.Character:FindFirstChild("RightPunch"):FindFirstChild("Handle"), {Player.Character)
LeftGripAttachment.Name = "LeftGripAttachment"
RightGripAttachment.Name = "RightGripAttachment"
newHitbox:SetPoints(LeftGripAttachment.Parent)
newHitbox:SetPoints(RightGripAttachment.Parent)
newHitbox:DebugMode(false)
Player.CharacterAdded:Connect(function(CharacterRes)
    local LeftGripAttachmentR = CharacterRes:FindFirstChild("LeftPunch"):FindFirstChild("Handle"):FindFirstChild("LeftGripAttachment")
    local RightGripAttachmentR = CharacterRes:FindFirstChild("RightPunch"):FindFirstChild("Handle"):FindFirstChild("RightGripAttachment")
    LeftGripAttachmentR.Name = "DmgPoint"
    RightGripAttachmentR.Name = "DmgPoint"
    newHitbox = RAYCAST_HITBOX:Initialize(CharacterRes:FindFirstChild("RightPunch"):FindFirstChild("Handle"))
    LeftGripAttachmentR.Name = "LeftGripAttachment"
   	RightGripAttachmentR.Name = "RightGripAttachment"
    newHitbox:DebugMode(false)	
end)

It works the first time but doesn’t work when the player respawns.

As a follow up, I’m using a function to ensure that it is not a typo in the characteradded event. The error is still present. Here’s the code:

function CreateHitbox(LeftGripAttachment, RightGripAttachment)
    local newHitbox2
    LeftGripAttachment.Name = "DmgPoint"
    RightGripAttachment.Name = "DmgPoint"
    newHitbox2 = RAYCAST_HITBOX:Initialize(Player.Character:FindFirstChild("RightPunch"):FindFirstChild("Handle"), {Player.Character)
    LeftGripAttachment.Name = "LeftGripAttachment"
    RightGripAttachment.Name = "RightGripAttachment"
    newHitbox2:SetPoints(LeftGripAttachment.Parent)
    newHitbox2:SetPoints(RightGripAttachment.Parent)
    newHitbox2:DebugMode(false)
    newHitbox = newHitbox2
end
CreateHitbox(Player.Character:FindFirstChild("LeftPunch"):FindFirstChild("Handle"):FindFirstChild("LeftGripAttachment"),Player.Character:FindFirstChild("RightPunch"):FindFirstChild("Handle"):FindFirstChild("RightGripAttachment"))

Player.CharacterAdded:Connect(function(CharacterNew)
    wait(4)
    CreateHitbox(Player.Character:FindFirstChild("LeftPunch"):FindFirstChild("Handle"):FindFirstChild("LeftGripAttachment"),Player.Character:FindFirstChild("RightPunch"):FindFirstChild("Handle"):FindFirstChild("RightGripAttachment"))
end)

Edit: After updating to version 3.2, the error disappears but the problem is still there, the hit isn’t registered.

Sorry about the late replies. Yeah the Signal error was caused by something in the old version.

Player.CharacterAdded:Connect(function(CharacterNew)
    wait(4)
    CreateHitbox(Player.Character:FindFirstChild("LeftPunch"):FindFirstChild("Handle"):FindFirstChild("LeftGripAttachment"),Player.Character:FindFirstChild("RightPunch"):FindFirstChild("Handle"):FindFirstChild("RightGripAttachment"))
end)

Regarding this code block, have you tried using the CharacterNew variable instead of Player.Character? From what i’ve tested, for some reason Player.Character can still have pointers to the old character until it has been garbage collected or updated. I currently would test but atm my hands are a bit full with projects. Let me know if it still doesn’t work and I’ll diagnose a bit further for you.

1 Like

I’ve changed the code to reflect your suggestion but to no avail. I think the problem is somewhere along the lines of what you said but I’m not sure. Here’s the new code:

function CreateHitbox(NewCharacter, LeftGripAttachment, RightGripAttachment)
    local newHitbox2
    LeftGripAttachment.Name = "DmgPoint"
    RightGripAttachment.Name = "DmgPoint"
    newHitbox2 = RAYCAST_HITBOX:Initialize(NewCharacter:FindFirstChild("RightPunch"):FindFirstChild("Handle"), {NewCharacter})
    LeftGripAttachment.Name = "LeftGripAttachment"
    RightGripAttachment.Name = "RightGripAttachment"
    newHitbox2:SetPoints(LeftGripAttachment.Parent)
    newHitbox2:SetPoints(RightGripAttachment.Parent)
    newHitbox2:DebugMode(false)
    newHitbox = newHitbox2
end

CreateHitbox(Player.Character, Player.Character:FindFirstChild("LeftPunch"):FindFirstChild("Handle"):FindFirstChild("LeftGripAttachment"),Player.Character:FindFirstChild("RightPunch"):FindFirstChild("Handle"):FindFirstChild("RightGripAttachment"))

Player.CharacterAdded:Connect(function(CharacterNew)
    CreateHitbox(CharacterNew,CharacterNew:FindFirstChild("LeftPunch"):FindFirstChild("Handle"):FindFirstChild("LeftGripAttachment"),CharacterNew:FindFirstChild("RightPunch"):FindFirstChild("Handle"):FindFirstChild("RightGripAttachment"))
end)

Thanks!

After even more testing, I have found the solution to the problem. Somehow the newHitbox variable doesn’t change the hitbox to the new one when the player respawns in the newHitbox.OnHit event. I had to put the newHitbox.OnHit event into the function so that it registers the correct new hitbox. For others to reference when met with the same problem in the future:

local newHitbox
function CreateHitbox(NewCharacter, LeftGripAttachment, RightGripAttachment)
    LeftGripAttachment.Name = "DmgPoint"
    RightGripAttachment.Name = "DmgPoint"
    newHitbox = RAYCAST_HITBOX:Initialize(NewCharacter:FindFirstChild("RightPunch"):FindFirstChild("Handle"), {NewCharacter})
    LeftGripAttachment.Name = "LeftGripAttachment"
    RightGripAttachment.Name = "RightGripAttachment"
    newHitbox:SetPoints(LeftGripAttachment.Parent)
    newHitbox:SetPoints(RightGripAttachment.Parent)
    newHitbox:DebugMode(false)
    newHitbox.OnHit:Connect(function(hit, humanoid)
	    -- Do stuff
    end)
end

@TeamSwordphin Thanks for your help!

2 Likes

Hi, I just started using this module. Is there any way to hide the ray cast beams. I looked on the documentation but I didn’t see how on there

You can use open up the module and turn off debug or use DebugMode function on the hitbox.

1 Like

Hey, I’ve been having a question for a long time, and I think it’s time to get an answer directly from the creator of this module. I have a melee combat system, but not with weapons, but with players’ parts. I use your module to detect hits, and how I do it is with a normal part with 5-6 attachments on it, that serve as hit points. Is this module good also for this kind of melee, or is it specific for weapons only? In any case I currently don’t have too many problems, except some missed hits sometimes.

This module is designed for all types of melee or hitbox combined. There is no right or wrong way to use this. It is up to the game creator to utilize it in a way that matches their game.

Yes, while this module uses weapons as an example, those are merely just one way to get the point across with this module. Many players on this thread has used it for unorthodox methods, such as boulder collision, hand to hand combat, lasers, and many more that aren’t specific to weapons.

1 Like

Alright, thank you! Yeah that’s what I kind of thought, but you know, it’s better to remove any doubts before continuing with it haha.

1 Like

I’m new to these types of hitboxes, but I have found problems with .Touched. Should I stick with what I am doing or use your hitboxes? I am testing your hitboxes right now but I don’t know how to enable Part Mode (V3) with your module. Also, I have the red line raycast hitbox thing working, but how do I disable it after like 3 seconds for an attack, not just a lingering hitbox, and how do I make it so the trail/hitbox (red lines) last shorter?

Only if you really need to use hitboxes that has raycasts. If you have slow moving physics based objects that uses touched, it may be fine to leave them as is. However, if you want to improve performance while also having much more control over where your hitbox is, this module can help with that.

There should be an advanced usage section on thr github link above showing how to turn on partmode. Refer to it as there are some minor drawbacks to using it but not big enough to be a concern.

local Hitbox = raycastHitbox:Initialize(obj)

Hitbox:PartMode(true)

You can use an accurate time scheduler to make the hitbox disappear after 3 seconds (one example being Promise). Using normal wait(3) is also fine but if you have a lot of hitboxes it will throttle and if the game starts lagging, wait(3) will become much longer than 3 seconds (there are many topics here on the DevForum explaining why using waits can be bad if used improperly)

The red lines are merely debug rays showing you where the hitboxes are and should not be used for production in case you are wondering. You can make it disappear quicker in the Debug module inside raycasthitbox. (Theres a dedicated module simply for visualizing the raycasts)

Hello I’m a little bit new to scripting on Roblox. I’ve followed the guide for creating a hitbox for my sword, the script does work and creates a hitbox for my sword. However the script only seems to work if the sword is in the workspace upon starting the game and does not seem to do anything if the sword is Cloned into workspace from ReplicatedStorage.

Been having an issue with this module. The hit detection seems to be unreliable, mostly when you’re stationary. Here’s an example of the issue I’ve been having:

https://gyazo.com/72f67e857c2acd2e49135c4df67643c3

I tried adding more attachments but that didn’t seem to do the trick. I also print the “hit” parameter of Hitbox.OnHit to make sure it wasn’t actually detecting anything, and yea it’s not detecting anything. Any idea on what the issue is?

Is the hit detection done on the server or client? I’ve had this problem before and it’s usually caused by one of these two problems:

  1. Server side hit detection. Animations can make server-sided hit detection not reliable due to the low refresh rate of replication.
  2. HitStop was not called or HitStart was called before HitStop did. If you are using KeyframeReached, it may be a good idea to call HitStop again right before you call HitStart at the beginning of the animation to guarantee it resets since I found out keyframes are not guaranteed to always fire in a consistent order.

However, if this is a client-sided hitbox, it may be a good idea to review the ordering of your HitStart/Stop functions in your scripts and animations. If you are sure you got everything down, feel free to share a portion of your script here and I’ll happily take a look at it to see if there are anything strange that I can pick up.