Raycast Hitbox 4.01: For all your melee needs!

That’ll be great! I’ll be sure to credit you once it’s finished! I know this will help a lot of people and save a lot of time!


@ncs03082 Looks like there’s a problem on how I wrote the raycastParams for the red line visualizers in the module. It actually does work but for context, the module isn’t ignoring the debug red lines (so therefore they keep hitting the redlines thinking they are actual targets). Try ignoring the terrain in the meantime (which is where the red lines are parented to) and see if it works:

local hb = RayHB:Initialize(hitbox, {workspace.Terrain})

This should be fixed in the next module update. Thanks!

1 Like

The problem that @ncs03082 has, might also happen to many people so I was thinking you should use handle adornments to avoid the rays hitting the debug parts. Secondly, so that people that have other parts in parented to terrain would not have the parts blacklisted.

1 Like

Damn, I was missing out. This really helped me out with my lightsaber system. Thank you for this awesome module! :heart:

1 Like

How do I make the laser rays invisible?

1 Like

it would be nice if u gave a parameter to set the gap between 2 points and i have code for smthg similar to this if it might help u, i used it for making attachments automatically

for i= part.Position.Y - part.Size.Y/2, part.Position.Y + part.Size.Y/2,0.75 do
			for x = part.Position.X-part.Size.X/2,part.Position.X + part.Size.X/2,1 do
			local currattach = Instance.new("Attachment");
			currattach.Name = "DmgPoint";
			currattach.Parent = part;
			currattach.WorldPosition = Vector3.new(x,i,currattach.WorldPosition.Z);
			end
		end

i doubt this will help but here u go

2 Likes

Inside the module, there is a property called DebugMode, turn that to false.

How would you make a functioning sword that is reliable with this module? I tried doing this method, firing the remote from a local script inside a sword. However, it does not work, and I think I found the reason.

Even tho I passed in the ignore argument in local RaycastHitBox:Initialize(handle, dontDamage), the newHitBox.OnHit still fires picking up the humanoid that is told to be ignored, then not allowing any other humanoids to be detected as it can only damage one humanoid at a time. When I take out the ignore argument, the newHitBox.OnHit actually fires, which it does not when the ignore argument is left in RaycastHitbox:Initialize.

Help would be appreciated I am struggling greatly with this issue

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")

local SwordDamage = require(ReplicatedStorage.Modules.SwordDamage)
local RaycastHitbox = require(ReplicatedStorage.Modules.RaycastHitbox)
local SwordRaycastPositions = require(ReplicatedStorage.Modules.SwordRaycastPositions)

local cooldown = require(ReplicatedStorage.Modules.Cooldown).cooldownValue

local humanoidsKilled = {}

ReplicatedStorage.Remotes.OnSwing.OnServerEvent:Connect(function(player, handle)
	local playerTeam = nil
	local playerToDamage = nil
	
	if remoteData[player.Name].SwingHandlingDebounce == true then return end
	
	local debounce = remoteData[player.Name].SwingHandlingDebounce
	
	if not debounce.Value then
		print("hello1")
		
		debounce.Value = true
		local character = player.Character or player.CharacterAdded:Wait()
		local dontDamage = {character}
		
		local damage = require(ReplicatedStorage.Modules.SwordDamage)[handle.Parent.Name]
		local newHitBox = RaycastHitbox:Initialize(handle, dontDamage)
		
		newHitBox:SetPoints(handle, SwordRaycastPositions[handle.Parent.Name])
		
		newHitBox.OnHit:Connect(function(hit, humanoid)			
			--just for test purposes on dummies
			
			
			humanoid:TakeDamage(10)
			
			--local playerTeam = player.Team
			
			--local playerToDamage = Players:GetPlayerFromCharacter(humanoid.Parent)
			--if playerToDamage ~= nil then
			--	print(player.Team)
				--if tostring(playerToDamage.Team) == tostring(player.Team) then
				--	print("DO NOT DAMAGE")
				--elseif tostring(playerToDamage.Team) ~= tostring(player.Team) then
				--	print("DAMAGE, THEY ARE THE ENEMY")
				--	humanoid:TakeDamage(damage)
				--end
			--end
			
		--	local leaderstats = player.leaderstats
			--local kills = leaderstats.Kills
			
		--	local enemyTeam = nil
		--	local playerTeam = player.Team
			
			--[[if table.find(humanoidsKilled, humanoid) == nil and humanoid.Health <= 0 then
				table.insert(humanoidsKilled, humanoid)
				kills.Value = kills.Value + 1
			elseif table.find(humanoidsKilled, humanoid) == nil and humanoid.Health >= 0 then
				table.remove(humanoidsKilled, humanoid)
			end]]
		end)
		
		newHitBox:HitStart()
		
		wait(cooldown)
		
		newHitBox:HitStop()
		
		debounce.Value = false
	end
	
end)

At first glance, that should be working correctly. Are you sure you didn’t set the hitbox’s raycastParams to Whitelist by accident somewhere? Have you modified the module in any way?

Does the ‘handle’ ever disappear if the character respawns? The hitbox will still be blacklisting the character’s old model if it doesn’t. You can try modifying the raycastParams of the hitbox directly to see if this fixes it:

local newHitBox = RaycastHitbox:Initialize(handle)

newHitBox.raycastParams = RaycastParams.new()
newHitBox.raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
newHitBox.raycastParams.FilterDescendantsInstances = dontDamage

Yeah, it does work, and no i didn’t seth the hitbox’s raycast params to whitelist. My only issue is when Im running through a gameloop and then when I wanna equip a sword, the damage doesn’t work correctly. But however, if I equip the tool outside the gameloop, it does work.

Its just a bit buggy when I equip the sword to the player, the damage sometimes doesn’t work, I can drop you a download example if you like.

Sure, I can take a look at the example place. You can shoot me it in my DMs.

Hey, found the problem. It was my mistake, so my game loop was designed so that it teleported all the players humanoidrootparts using position not CFrame, therefore messing up the positions where the rays were casted.

3 Likes

Hello,

Any ideas on why it doesn’t hit some of the times on certain angles ? Thank you ^^

https://streamable.com/20veek

Hello!
I am trying to make a parry system where if you press a certain key, it will activate the parry. If player(A) attacks player(B) that is parrying, player(A) won’t be able to move for a few seconds. What do you think the best way to do that?

1 Like

Looks like it isn’t taking into consideration the hat when it gets hit (from what I see at least). There is also currently a little glitch with the red line visualizer that can make hit detection less accurate (will be fixed sometimes today), so try turning off the red lines and hitting normally at the angle to see if it persists.

1 Like

Seems like a topic this broad would be better off in development discussion or scripting support, but I’ll give some insight anyway.

My game uses a similar styled parry system where one can parry another. There are a few ways to achieve this.

  1. A “hurtbox” of sorts. When player B parries, an invisible brick (or you can use attributes here somewhere for the player B) will appear alongside their weapon. You can then see if PlayerA hit this hurtbox, which if they do, they are parried. This is the most accurate way of seeing parries.

  2. Animation checking. When player A strikes player B, instead of dealing damage, check if player B is playing the parry animation. Downside is that this method can sometimes be unreliable.

  3. Status effect (personally how I do it due to the sheer amount of enemies in my game). Player B, upon playing the parry animation, is tagged with a “Parry” status effect for a second. Player A strikes Player B, and seeing that they still had the Parry status effect, becomes parried. This same logic can also be simplified wholely with attributes.


There is no right or wrong way to do it so it will be up to your own preferences.

1 Like

Is there any way I can optimize this?
https://gyazo.com/28ad894f9e1d54a0fbdbb5e34b9d1549
The rays don’t appear as fast as I’d like them to. Is there somewhere I have to edit?

If this is server-sided, that is latency you are experiencing and there are no known ways to fix this other than porting your hit detection to the client.

1 Like

How would i go about using GetHitbox on a part through a localscript?

This is the current code that i have, the hitbox is initialized but the variable hitBox is still nil

hitBox = RAYCAST_HITBOX:GetHitbox(character:WaitForChild(“Axe”))

Any help would be appreciated.

If the hitbox is initialized on the server-side, the module will not be able to see it. You will need to manually initialize the hitbox on both server and client. The hitbox also disappears when the Axe is deleted or destroyed (or respawns with the character) so reinitialization is needed.

1 Like