How can I raycast a part

I want to raycast a line basically from the part position to the end of the part

The part is a thin line

local results = workspace:Raycast(line.Position,((line.Position + line.Size) - (line.Position - line.Size)).Unit * 500)

It works sometimes if the line isn’t on certain angles
so I’m wondering how I can improve on it and make it work a bit better.

go here for info: Raycasting | Documentation - Roblox Creator Hub

Thats not what I’m looking for.
I know how to raycast
I’m trying to raycast a part like legit the part itself
I just don’t wanna use touched but I probably will if I can’t figure it out

I want to raycast a line basically from the part position to the end of the part

That’s exactly what the link teaches. workspace:Raycast raycasts from the first parameter, and moves in the direction of the second.
workspace:Raycast(rayOrigin, rayDirection)

That said, I can’t explain why you might be having issues.

I’m looking for basically a raycast to cover a part so anything that is inside the part is incased and will return a result. So yeah I was kind of confused why it didn’t work so I decided to ask about it.

For example:

Since it is in the line it should return the object
but what happens is that it only returns it if its directly straight from where the point is and only a bit left or right.
If you go very far right or left you can still be in the part but it won’t return anything
Also don’t want to raycast directly to the character as that makes the part undodgeable it’s going to be used for something that should be dodgeable but it does work

in that case why don’t you use region3 instead

Its an angled blocked and region3 seems kind of annoying

you might find something in this post helpful

That’s nice and would probably solve my issues but you know I just want to know how to create a raycast according to what I need.

Again, if I can’t find an answer or explanation on how to do it I’ll just use a touched event or something

I’m guessing you’re trying to raycast from a part’s front to the back

local from = (part.CFrame *,0,0)).p

will get you the part’s front

local p = (part.CFrame*,0,0)).p

will get you it’s back, now you need to turn it into a direction with

local direction = (from-p).Unit*-part.Size.X

and raycast using “from” and “direction”

Not quite, I’m looking for directly in the center of the part is kind of what I’m looking for

I’m not sure how @Tomatoe_s solution doesnt work but another way is to use the parametric line equation and only give positive values of t. It basically returns a point on a ray (assuming t is positive). Just make sure the direction is defined as the difference of the two vertexs, eg: direction = rayOrigin - objectPosition

for i=1,100 do
  local part ="Part")
  part.Anchored = true
  part.CanCollide = false
  part.Position = rayOrigin + (rayDirection.Unit * i)
  part.Parent = workspace

Yeah sorry this probably won’t work either but what I figured out is that I can put two parts make them invisible parts raycast them and that should work

So yeah I tested it with what I thought and it actually worked very well thanks for the responses though