How would I make a ray go through a part?

Hello! I’m working on a first person shooter game and I was wondering if I could make the ray go through bullet holes? I tried using FindPartOnRayWithIgnoreList but it didn’t work. The ray just stops when it hits a bullet hole. Code:

local RayCast = Ray.new(					
bruh, -- vector3 of the mouse
(ToP-bruh).unit*500
)
local ignoreList = workspace.bh:GetChildren() -- folder with all the bullet holes
table.insert(ignoreList,plr.Character) -- player's character
local Part,Position,Normal = game.Workspace:FindPartOnRayWithIgnoreList(RayCast,ignoreList, false,true)
if Part then
print(Part.Name)
local Dist = (ToP-bruh).magnitude
if not Dist then Dist = 300 end
 local Hole = game.ReplicatedStorage.Hole:Clone()
 Hole.Parent = workspace.bh
 Hole.Position = ToP
 Hole.CFrame = CFrame.new(Hole.Position, Hole.Position+Normal)
game.Debris:AddItem(Hole,3)

Any help would be very appreciated! :smile:

1 Like

The solution I have seen to (and used for) this is just adding more parts to the ignore list and repeating your raycasting.
So it could be something like this I guess:

local counter = 0
local Part, Position, Normal
repeat
    counter = counter + 1
    Part, Position, Normal = workspace:FindPartOnRayWithIgnoreList(...)
    table.insert(ignoreList, Part)
until SomeCondition() or counter > 3 -- or 5 or whatever

As long as you don’t make your rays too long, like the max distance of 5000, it shouldn’t be very expensive.

1 Like