Raycast Hitbox 4.01: For all your melee needs!

can this be used to make a shield hitbox?

How can I put the attachments on the players arms?

1 Like

@epictitanic6g This module does not discriminate hitbox sizes. So yes you can. It is designed to be universal and not simply for swords.

@ErskinePierre I would consider looking up Roblox tutorials or asking around the Building/Support subforum as that is out the scope of this module.

A good starting point on what and how to insert attachments can be found here. This module does not use constraints, but it does use attachments the same way constraints require them.

2 Likes

@TeamSwordphin Hi, I see that the OnHit function has a rayresult thingy but I am looking for the HitPosition of the ray which hit, how would I get it? Im assuming with that rayresult thingy but there isnt much detail about it so idk what to do

It is a RaycastResult parameter. See Documentation:

Hitbox.OnHit:Connect(function(hit, humanoid, raycastResult)
     local hitPosition = raycastResult.Position
     print(hitPosition)
end)
1 Like

@TeamSwordphin How much “DmgPoints” Attachment would be considered a good amount to insert inside a players arm or leg?

General rule I like to use while working with this module is “enough to make it feel good/accurate, but not a lot where there are redundant attachments”. If your hits are not registering, add a bit more attachments.

A good number I generally see myself using is around 9 DmgPoint attachments per hitbox (spread out 1 stud apart). Thicker hitboxes like the arms/legs will need the attachments spread out a little more and in some cases, you might need to add more.

Overall, this module is already quite efficient since raycasting doesn’t really net a huge performance overhead so you should be fine running a lot more than 9.

Oh ok thanks ill use a bit more then because sometimes the ray origin is inside a players body part when i punch so it wouldn’t register.

Yah it can, I don’t see why you think it can’t.

I can’t believe I only found this module just now—it’s like all of my combat prayers have been answered! I’ll be implementing the V2.2 Stable into my game over the next couple of days. If I find any bugs I’ll be sure to post them.

Thank you for making this. It’s seriously a blessing.

1 Like

even if its an old hitbox, its extremely simple to use and will make for great hitboxes that need to be precise!

This is an excellent release!
Exactly one of the few things I couldn’t think of but is an intriguing asset, thank you. :+1:

2 Likes

Hey, I’m having trouble using this. Basically the damage given to the NPC gets multiplied everytime a player swings, For example it starts off at 5 and if a player swings twice it and if the second hit hits an NPC the NPC will be damaged for 10 instead of 5.Heres my code:

–[ Variables ]–
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local Remotes = replicatedStorage:WaitForChild(“Remotes”)
local SwingRemote = Remotes:WaitForChild(“Swing”)
local ShovelData = require(game:GetService(“ServerScriptService”):WaitForChild(“Modules”):WaitForChild(“ShovelData”))
local replicatedData = replicatedStorage:FindFirstChild(“replicatedData”)
local NPCFolder = game.Workspace:FindFirstChild(“NPC’s”)

local RAYCAST_HITBOX = require(replicatedStorage.Modules.RaycastHitboxV2)

local CanDamage = true

–[ Main ]–
SwingRemote.OnServerEvent:Connect(function(Player)
if CanDamage == true then
CanDamage = false
local playerCurrentShovel = replicatedData:WaitForChild(Player.UserId).CurrentShovel.Value
local Character = Player.Character or Player.CharacterAdded:Wait()
local Shovel = Character:WaitForChild(playerCurrentShovel)
local DamageToTake = ShovelData[playerCurrentShovel].Damage

    local newHitbox = RAYCAST_HITBOX:Initialize(Shovel.Handle)

    newHitbox:HitStart()
    doDamage(Shovel, newHitbox)
    wait(.1)
    newHitbox:HitStop()
    CanDamage = true    
end

end)

function doDamage(Shovel, HitBox)
local Character = Shovel.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local playerCurrentShovel = replicatedData:WaitForChild(Player.UserId).CurrentShovel.Value
local DamageToTake = ShovelData[playerCurrentShovel].Damage

HitBox.OnHit:Connect(function(hit, humanoid)
    if hit.Parent ~= Character and hit.Parent.Parent == NPCFolder then
        local hitNpc = hit.Parent.Humanoid
        hitNpc:TakeDamage(DamageToTake)
    end
end)

end

You need to disconnect the Hitbox.OnHit function afterwards so the damage doesn’t multiply.

local Hitbox = HitBox.OnHit:Connect(function(hit, humanoid) --Hitbox Function
--your code here

end)

Hitbox:Disconnect() --Needed to disconnect the function

I’m trying to set up hitboxes in both of the players arms.

I could use:

local ArmsHitbox = RAYCAST_HITBOX:Initialize(chr, {chr})

But I have hitbox attachments in the players legs so that won’t work.

I’ve tried using this:

local ArmsHitbox = {RAYCAST_HITBOX:Initialize(chr["Right Arm"],chr["Left Arm"],{chr}}

But the code above doesn’t work at all. How can I make it so that it only gets both arms and nothing else?

This may be a stupid question, but does the raycast ignore humanoids if it’s not a direct child of the workspace? I tested this by placing a dummy inside the workspace within a folder, but the raycasts didn’t detect the humanoid. Is there a way this can be supported?

The raycast actually can detect humanoids inside folders. There might be an underlying issue with your script.

If you want to do this without using :SetPoints(), you may need to do a bit of hacky method (or til I implement some sort of grouping feature).

You can possibly rename the attachments in the legs to something else for now, then call

local ArmsHitbox = RAYCAST_HITBOX:Initialize(chr, {chr})

and then rename the attachments in the arms to something else, and rename the leg attachments back to DmgPoint, then do

local LegsHitbox = RAYCAST_HITBOX:Initialize(chr, {chr})

Double-check you aren’t accidentally putting the folder in the ignore list as well. Otherwise, this module does not discriminate on where parts are descendants of, as long as there is a humanoid it will detect it.

How can I use :SetPoints() to achieve my goal?

My bad, the raycasts DO detect humanoids even if not a direct child of the workspace. However, I noticed that the raycasts were not detecting the humanoids because of differing collision groups. I tested this by changing the the collision groups of two dummies, one with the same collision group as object with the raycast, and the other dummy with a differing collision group. It detected the humanoid of the dummy with the same collision group as the object, but not with the other dummy. Can this be supported?

1 Like