Raycast Hitbox 4.01: For all your melee needs!

Sure, no problem! Thanks for being so supportive and responsive. I really appreciate it!

1 Like

ya be kinda speaking some fax :hot_face:

@TeamSwordphin Hello there! I am using your raycast hitbox for my melee mechanics, but when I slash with the tool it will damage myself and THEN damage someone else. Is there a way to blacklist myself so it won’t detect a local player?

You can use RaycastParams.

hitbox.RaycastParams = RaycastParams.new()
hitbox.RaycastParams.FilterDescendantsInstances = {myCharacter}
hitbox.RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist
1 Like

Solved! Just used CFrame rather than position to teleport the player and it worked like a charm. Not sure why thought :thinking:.

1 Like

I don’t actually use this module, I like it a lot, I find it pretty good, I don’t use it because I don’t work with front-end stuff.

I wonder why you went with still having a “Signal” module anyway? It doesn’t behave like a normal event, it can only have one connection, it doesn’t have any other features like :Wait, they’re more like a callback, so why not just go with a normal callback?

I know you might have you know, keep some things similar to older versions, but I feel like it was kind of a missed opportunity with the release of 4.0, I know that you made that Signal to be as instant as possible, obviously, but in that case you could just make it into a normal callback,
and it would be even faster to call too.

function Hitbox.OnHit(hit)
    print(hit)
end


--// Fire

local _onHit = self.OnHit
if _onHit then
    task.spawn(_onHit, hit) --\\ You can use `task.defer` too, it will run later though of course. Don't know how that affects your use-case.
end

If you were to go with an actual signal instead of just making it into a callback, then I recommend GoodSignal or FastSignal

GoodSignal is interesting for your use-case because it has routine recycling which is really cool for use-cases like yours which might require it to fire super quickly.

How would i convert my v3 to v4?

local plr = script.Parent.Parent.Parent

local char = plr.Character

local idle = char.Humanoid:LoadAnimation(script.Animations.Idle)

local equipped = false

local attacking = false

local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV2)

local Hitbox = RaycastHitbox:Initialize(script.Parent.Weapon)

durability = 7

local attack1 = char.Humanoid:LoadAnimation(script.Animations.Attack1)

local broken = false

Hitbox.OnHit:Connect(function(hit, humanoid)

if humanoid.Parent ~= char and humanoid.Parent.Handler.Infected.Value == true then

script.Parent.Weapon.Hit:Play()

local damage = math.random(15,35)

local Speed = 25

local Force = 40000

local TotalForce = Force

local KnockBack = Instance.new("BodyVelocity",hit.Parent:FindFirstChild("Torso"))

KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)

KnockBack.Velocity = plr.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Speed -- based on the direction YOUR character is facing.

game.Debris:AddItem(KnockBack,0.1)

humanoid:TakeDamage(damage)

humanoid.Parent.Actions.Stunned.Value = true

if durability == 0 then

Hitbox:HitStop()

script.Parent.Weapon.Transparency = 1

script.Parent.Weapon.B:Play()

script.Parent.Weapon.ParticleEmitter:Emit(50)

game.ReplicatedStorage.EditGUI:FireClient(plr,"text","Your baseball bat broke.")

broken = true

idle:Stop()

attack1:Stop()

wait(2)

script.Parent:Destroy()

end

durability = durability - 1

end

end)

script.Parent.Equipped:Connect(function()

if not plr.Character.Actions.Stunned.Value == true and not broken then

idle:Play()

equipped = true

else

plr.Character.Humanoid:UnequipTools()

end

end)

script.Parent.Unequipped:Connect(function()

idle:Stop()

equipped = false

end)

script.Parent.Activated:Connect(function()

if not attacking and equipped and not plr.Character.Actions.Stunned.Value == true and durability >= 0 then

attack1:Play()

attacking = true

script.Parent.Weapon.Prepare:Play()

wait(0.16)

Hitbox:HitStart()

script.Parent.Weapon.Swing:Play()

wait(0.4)

Hitbox:HitStop()

wait(2)

attacking = false

wait(0.4)

end

end)

plr.Character.Actions.Stunned.Changed:Connect(function()

plr.Character.Humanoid:UnequipTools()

end)

Good point. I already have a newer version utilizing GoodSignal and task which both supports the single callback and multiple connections (not sure when I’ll update), but thanks for the heads up. I’ve been meaning to get rid of the older signal module for a while now but I decided to wait until tasks were officially released.


@DogGuyTheThird You tried looking at the main post? I put some instructions on how to convert it.

2 Likes

I couldnt find it? can you show it to me?

The bottom of this post contains the new APIs, basically, you just need to switch out the old methods with the new ones. It shouldn’t take too long.

1 Like

so since:

  • Removed RaycastHitbox:Initialize
  • Removed RaycastHitbox:Deinitialize

got removed do I have to:

RaycastHitbox.new
Hitbox:Destroy?

When I use this for melee with Default Detection, it doesn’t hit player’s torso and head, because of accessories, is there a way to fix it?

1 Like

Look. Just make a server-sided script that will change accessory’s size to (0.05, 0.05, 0.05). It’s the easier way to deal with most of “ghost-hits”.

Hi, I have a basic combat system no melee, how can I implement this module instead of using a big hitbox on the hands for punching.

1 Like

This is a smart method though, Thanks!

1 Like

I have a hitbox set up that creates the hitbox and starts it when a remoteevent fires but once it hits and disables the hitbox, another firing of the remote doesn’t create the hitbox.

Seems like errors get eaten in the OnHit:Connect callback (making it difficult to debug)

Here’s an example where I explicitly throw an error in the callback:
RaycastHitboxNoError.rbxl (43.0 KB)

The module looks great! I’ve run into a problem, however, and I’m unsure of how to fix it.

I used your intermediate tutorial to make hitbox points along my character’s arms for a punching attack activated whenever “E” is pressed. The script on my end works fine, however, I get this error from the Vector3 script in the module.

Here’s the line the error stems from.

I imagine a possible reason for this error is because my script is a local script in StarterGui, but again, I’m unsure. Please let me know if you have any solutions to this error!

EDIT : Nevermind, it works fine! I corrected a mistake with what I set the hitbox points to and the problem is gone.

Well done! Works perfectly for punching/kicking which I had first worried about and is a great way to start of your own customized Raycast Hitbox script.

Suppose I’ve created a part and I create a hit-box using a script parented to this part, and I later destroy the part with :Destroy(), do I need to disconnect OnHit when I do that or does the module handle this for me automatically?