Raycast Hitbox 4.01: For all your melee needs!

yeah i didn’t think of that ur right !

1 Like

It still doing it arghhh . I’m sorry but can u show me how can i make just doing a damage to a single player without multiple damage because like i tested in ur test map and it do the same thing so .

That’s alright. Do you have the full damaging code you can share? This should in theory work. (Also make sure PartMode is also disabled, if you have that on it will also run the OnHit multiple times)

local HitboxConnection = nil
HitboxConnection = HitBox.OnHit:Connect(function(hit, humanoid)
	humanoid:TakeDamage(10)
	HitboxConnection:Disconnect()
    HitboxConnection = nil
end)

HitBox:HitStart()
wait(10)
HitBox:HitStop()

if HitboxConnection then ---If we still are left with an active HitboxConnection
	HitboxConnection:Disconnect()
	HitboxConnection = nil
end

Sorry but what is PartMode ? Is that a roblox thing or is that a value of ur Module ?

It is a value similar to DebugMode in the module. If you do not know what it is, then you don’t need to worry about it since it’s by default off. The sword that you tested in the test place had PartMode on, which is why it damaged multiple times (it’s to emulate how the Classic Sword worked).

If you still are having problems, consider moving this conversation to my personal DMs.

Is it possible to use it for lightsaber blade that leave a burned mark on the wall/floor/anything but I cant figure out how to make trail part to stay on the wall or floor or even everywhere is it possible to get it worked?

I hate to necro an old forum, but I have heard from a few people that there are optimization issues with this script. How significant are these issues, and at what scale, or under what use cases, should I expect to see these optimization issues be apparent?

Thank you for this module by the way, its awesome.

I have yet to receive reports of erratic performance issues that are with this module. If you have any further information for what type of optimization issues you were implying, please share them and I’ll try to see if I can improve on it.

Otherwise, it works just like any normal raycasting setup does. The longer the rays, the more performance-hungry it becomes. It also depends on how many raycasting is being done (I’ve only tried up to 780+ raycasting points a second for this module with minimal server lag). People also shouldn’t be running the rays 24/7. If you are running this module on the client-side, the only thing that will be holding you back is your framerates.

I’m always up to improve the module, but honestly, it also depends on what type of game you’re working with so there is no one answer to what determines the performance of this module.

3 Likes

I have been having an issue while loading the hitbox on a Local Script. attempt to index nil with 'Points' is my error. It works fine server-sided.

It would be helpful if you could provide your local script code and the specific line it errored on. There shouldn’t be a major difference if the module is required client sided or server sided. You should also try to redownload the module if you’ve done any modifications to it.

1 Like

Here is the code. Apologies for not posting it earlier. What I do is that I play an animation server-sided and use the animation events to trigger the Hitbox activating and deactivating. If it hits something, it is supposed to send it to the Server for checks and damage dealing.

It errors at the " Hitbox.HitStart() " section. Trying to warn the Hitbox object return the name of the Hitbox source, which is in this case my Character. The hitbox output also states it found all the attachments.

local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitbox)
RaycastHitbox:DebugMode(true)
local Hitbox = RaycastHitbox:Initialize(Character, {Character})

Hitbox.OnHit:Connect(function(hit, hum)
	Event:FireServer("HitEvent", hit, hum)
end)

Event.OnClientEvent:Connect(function(RequestType)
	if RequestType == "EndHitbox" then
		Hitbox:HitStop()
	elseif RequestType == "StartHitbox" then
		Hitbox.HitStart()
	end
end)
2 Likes

It should be a colon, not a period. :slight_smile:

3 Likes

:grinning: I revived this for nothing didn’t I?

2 Likes

New Update: V.2.0 EXPERIMENTAL

Hi all, I hope you all are staying safe amidst this pandemic. Things might get tough, it may not even be easy, but our strength comes from our perseverance. I have a new update, an update that can hopefully bring some relief or joy, no matter how little, to your already arduous lives.


This update brings in a boatload of optimizations. I have completely stripped, tore, and dismantled the entirety of the module. The module has been rewritten from the ground up and mainly was to fix how new threads were being used (which inevitably did increase performance with the more hitboxes you have). You won’t notice a difference if you were only using 1 hitbox in the entire game lol. There were also a lot of other things I changed / removed but those aren’t as important. I’m not the best scripter so do let me know what kind of improvements I can make.

Old Raycast Module: Each hitbox will make a new thread with their Heartbeat function.

New Version: No matter how many hitboxes there are, there will always be one centralized Heartbeat thread.

The API has remained largely the same, with some functions deprecated (refer to the main post). Anyone that dislikes this update, from now on, I will attach all previous modules (after V.1.53) at the end of the main post so you can rollback as you please.

Do let me know what bugs you guys find!


If anyone is interested in the performance test between the old and new module versions, lookie here

The most substantial test that I’ve did is having a 500-stud wide block with 600 attachments (or 600 raycasting points). I then cloned this 48 times (effectively around 28,800 raycasting points). The blocks are moving 200 studs a second going back and forth. I did this for both old and new raycast modules for about 5 minutes each. Debug Rays were off. Unfortunately, the Script Performance editor was useless since it doesn’t show the activity rates properly for the new module (always showed 0.00% activity, unless it actually is that much…) so I had to rely on framerates, game logic delays, and cold hard analysis.

OLD MODULE PERFORMANCE

RobloxStudioBeta_biSrAnDjcI
RobloxStudioBeta_9x47gpExvB
Starting with the Physics FPS, it went below 50/s a lot the times, and even times down to 10/s once I started moving the blocks. The Heartbeat was a lot lower, reaching a ceiling of about 13.5/s and dipping occasionally to 2 - 4/s.

NEW MODULE PERFORMANCE

RobloxStudioBeta_HYHYuuWUjZ

Like I mentioned before, the Script performance window is useless as it didn’t give any information at all. There were still some server side throttling but at a much manageable rate. Heartbeat was sticking around 16 - 17/s, making this effectively 15% faster than the old module. My Physics FPS was also sticking to 60 (or around 30/s once i start moving the blocks) the entire time which was pretty great.

Conclusion

Now, I’m still not satisfied with what I tested. If anyone has a better way of benchmarking, please let me know but I feel like I am happy with how this turned out. I also had to tune some of my hitboxing code in my games because of how less laggy it was. (for example, things that was supposed to hit once now hits twice since the hitbox resets targets so fast now)

14 Likes

@Swordphin123

Are you going to / Did you update the Module to use the new API

workspace:Raycast, raycastParams and raycastResult?

2 Likes

I will update it to the new API within the next few days.

3 Likes

New Update: V.2.1 EXPERIMENTAL

Credits to @RuizuKun_Dev for reminding me to update. Small revision but the module now uses the new Raycasting API. HitboxObject now has a raycastParam property and OnHit returns raycastResults now.

This means that if you want to use a Whitelist with this module instead, you can do so for specific hitboxes like so:

local RaycastHitbox = require(workspace.RaycastHitboxV2)

local Hitbox = RaycastHitbox:Initialize(Character, {workspace.Enemy})
Hitbox.raycastParams.FilterType = Enum.RaycastFilterType.Whitelist --- Was defaulted Blacklist

Hitbox.OnHit:Connect(function(hit, humanoid, raycastResult)
     print(raycastResult.Instance:GetFullName())
end)

This allows you to adjust each hitbox on the fly and according to your needs, which I think is pretty neat.

6 Likes

Hi I’m using your module and I’ve noticed that sometimes it wont hit even though it’s supposed to. Here’s a video to show what I mean, you can look at the last punch in the video how it doesnt damage the dummy like the other punches but the red ray goes through the dummy’s arm.

I would consider adding more DmgPoints to your arm. More on the width and length to be more accurate.

The reason it doesn’t hit sometimes is based on how raycasts fundamentally work. It fires a ray on its current position and last position per frame. However, if the current position was fired while inside a part during that frame (so, in this case, your limbs), it won’t register the hit. It only detects the hit if the ray’s current position was created outside of the part during the frame.

This is why I advise having more attachments, it makes it much more likely to hit as there will be more raycasts made outside the part on the frame.

3 Likes

I actually did like 18 and the same thing happened. like I literally covered the whole arm with dmg attachments and that still happened so im not sure what to do

1 Like