Raycast Hitbox 4.01: For all your melee needs!

It works with any basepart. But for fists it might be better to use something like rotated region3.

1 Like

Hey i seem to have an issue with the rays not firing properly the first time a player swings his weapon
Video:

And here is the code

		elseif input.UserInputType == Enum.UserInputType.MouseButton1 and equipped and not debounce then
			debounce = true		
			local slashAnimTrack = animator:LoadAnimation(slashAnim)			
			local hitBox = RAYCAST_HITBOX:GetHitbox(character["Axe"].HitPart)			
			--DamageEvent:FireServer()		
			hitBox:HitStart()			
			slashAnimTrack:Play()			
			wait(slashAnimTrack.Length)			
			hitBox:HitStop()			
			debounce = false
		end

And this code here which is also in the same local script as the above code initializes the hitbox when the weapon is instanced.

function initHitbox(weapon, equipped)	
	if not equipped then
		local RayPoints = require(RS.RayPoints)	
		local char = player.Character	
		local ignore = {char}	
		local newHitbox = RAYCAST_HITBOX:Initialize(char:WaitForChild("Axe").HitPart, ignore)
		newHitbox:DebugMode(true)
		newHitbox:SetPoints(char[weapon].HitPart, RayPoints[weapon])


		newHitbox.OnHit:Connect(function(hit, humanoid)
			print('Damaged')
		end)
	end
end

If you have any idea what is causing this issue or if you need more information that can help you help me resolve this problem then please let me know thanks.

2 Likes

Had the exact same problem basically your using the length of the animation track but the animation track isnt loaded and by default its set to 0. You could use an animation event to try fix it I havent got round to solving mine yet.

2 Likes

God i feel like a complete idiot. The way i decided to fix it was to load the animation at the start of the script instead of at the start of the function. Thanks for the help!

2 Likes

You tweened the HRP? I feel like it should work perfectly normal but if you want the character to move just use a body mover.

Set the parent of the attachments you’re using the HumanoidRootPart. It doesn’t get affected by animations.

is it possible for u to put in the attachment tht detected it as a paramete

8 days later i just had the same issue, did u find a solution for it?

it is detecting the RayCastHitboxDebugPart when debug is on not a problem for me but might be for others

Try keyframe reached or marker reached might help but I didn’t solve it due to quitting that project

1 Like

mmm @TeamSwordphin u accidently marked the wrong post as solution

@crazygamer817 Thanks, haha just woke up and accidentally clicked it.

It’s possible, though is there a specific use case for why? The group feature can accomplish this, if you need one attachment specifically you can designate a group name for it.

There was an alternative solution which I personally use which often guarantees animations to not return zero length here:

1 Like

stuff like knocback etc getting position for hit effects etc. the grp thing needs unneccessary instances which cn get a bit laggy for me since i have a lot of weapons and also there r a lot of weapons and its like too much work, i cn like change the module for myself specifically too but thought this would be a useful feature

edit 1:

i feel u man except i make such mistakes cuz of no sleep

edit 2:
i for one am gonna be using this a lot in hit effects knockback calculations damaging etc etc. i am working on tht advanced sword combat system tht i might open source with limited features later

1 Like

I love the whole module, but I think the default name of hitpoints should be “Hitpoint” instead of “DmgPoint” because this doesn’t just have to be used for weapons.

I have a knife-throwing script, it works fine for damages, but I can’t seem to figure out how to get it to stop once it has hit a wall or something. Is there any way I could fix it? No errors in the output btw.

spawn(function()
	local Damage = 50
	local Hitbox = RaycastHitbox:Initialize(Knife, char:GetDescendants())

	Hitbox.OnHit:Connect(function(hit, humanoid)
		if donefor then return end
		print(hit.Name)
		if humanoid:IsA('Humanoid') then
			if humanoid.Health == 0 then return end
			if Instakill then humanoid:TakeDamage(humanoid.MaxHealth) else humanoid:TakeDamage(Damage) end
			Knife:Destroy()
			thri:Play()
			print('Humanoid')
		end
		local part1 = hit:FindFirstAncestorOfClass("Model")
		local part2 = yo1:FindFirstChildOfClass("Humanoid")
		if not part1 or part2 then -- check if it should be a wallknife (this is the part where nothing happens)
			Knife.Anchored = true
			Knife.Cancollide = false
			Knife.Name = 'WallKnife'
			knifeBV:Destroy()
			thri:Play()
			print('Wall')
		end
	end)

	Hitbox:HitStart()
	wait(3)
	Hitbox:HitStop()
end)

I’m going to go insane it says if not part1 or part2 oh my god I have been throwing at models god I strongly dislike life. I forgot to add “not”

i just finished tht and am working on dmg calculations so well i kind of need a way to see how long the hitbox has touched the part and when it leaves and stuff is smthg like this possible if so could u gimme some sort of guidelines for doing so

Unfortunately not possible due to the nature of how raycasts work on Roblox. Rays only listens for intersections of parts and does not know whenever it has left or entered a part.

so wht if i set up a link between the top and bottom end and maybe set up a table for the parts it saw in the previous detection do another detection in between frames and if its not there now then it left. would smthg like tht work?

It might, though that will be up to you to implement it. The module automatically omits already-detected parts for performance reasons. This makes sure other rays don’t accidentally call its hit detection twice. If you don’t want the module automatically ignoring parts it has already hit (for example, might be good for your use case), you can look at the MainHandler script in the module, and commenting out

Object.targetsHit[target] = true
1 Like