Help with raycast

Im not sure if its my problem, but the weapon hitbox doesnt work.
I used your script with some changes for debugging, yet it didnt work.

Am I missing something?

Where are the attachments located in world space, and why are attachment positions being used in particular?

Im trying to make a weapon that does damage using raycasts cause .touched is unreliable.
The attachments are inside of a part of a weapon and scale from the bottom of the blade to the top

I am using attachments so I dont have to create a ton of parts

A .Touched event might be more suitable for a sword than rays. If you’re worried about the event being unreliable, you could add a debounce or lock variable to stop it from firing too many times in one swing.

Yeah, I tried a touched event already though.

Lets say it didnt go to plan…

It fired constantly even after I put a debounce.

If you wanted rays you could just use this module; Raycast Hitbox 4.01: For all your melee needs!

I already looked at that. It does not suit me very well, and I would much rather script it myself because thats how I learn. I dont learn by just slapping models into my tool

Its a module not a model and if you wanted I can help you with raycasts

I dont want someone to personally teach me, I find more fun in scripting by learning it myself and sometimes asking for help

Understandable, but here is what I did if you needed help; local origin = ((yourorigin)) local direction = (mouse.Hit.Position - origin).Unit * MaxRayDistance local rayParams = RaycastParams.new() rayParams.FilterDescendantsInstances = {workspace.Baseplate, player.Character} rayParams.FilterType = Enum.RaycastFilterType.Blacklist local result = workspace:Raycast(origin, direction, rayParams)

1 Like

Okay. Thanks for the help. I appreciate it

1 Like

I appreciate your enthusiasm to learn and try things out for yourself, but it’s much easier to use existing code than reinvent the wheel. Besides, nothing stops you from examining the module’s code and learning it that way, even if you don’t want to use it.

Aside from that, if the module didn’t suit you, it’s unlikely that using raycasting techniques for hitboxes will either; I’d still recommend using a .Touched event. Did you enable the debounce variable correctly when you tried it last time?

Touched events are still very unreliable. A magnitude check might be better for accuracy.

Yes. When I used the touched event, I made it able to disconnect so it wouldnt do damage when the sword wasnt swinging. That didnt change anything, though. When the sword already swung, it did damage after the animation was done

Exactly. My friend made a touched event weapon and it fell into shambles. Touched events are also heavily unreliable for falling objects that do damage. If you just stand still, the touched event wont fire.

You could use instance to make the hitbox part and cframe and parent it to the area you want it and then destroy it using :Destroy() make sure you use debounce

Yeah, but I feel like it would… feel unreal.
I also tried that on another script, it just didnt feel right to me.

The only option I have right now to fix the ray is fire the ray from the characters HumanoidRootPart. But that would mess up all the hitboxs’

You could fire it from parts created with attachments

Yeah, I did, Thats basically my broken hitbox script right now. And I dont want my script to look like this:

local ray = workspace:Ray(attach1, attath0 "stuff")
local ray2 = workspace:Ray(attach1, attath0 "stuff")
local ray3 = workspace:Ray(attach1, attath0 "stuff")
local ray4 = workspace:Ray(attach1, attath0 "stuff")
local ray5 = workspace:Ray(attach1, attath0 "stuff")
local ray6 = workspace:Ray(attach1, attath0 "stuff")
local ray7 = workspace:Ray(attach1, attath0 "stuff")

You can just try using the module its incredibly helpful, but its okay if you dont want to its your choice.