As shown in this clip, the raycast only works for the left and front direction, how would I make it work for all directions?

Script :

local Part = script.Parent
local HitBox = Instance.new("Part")
local RP = RaycastParams.new()
local FilterDescendantsInstances = { HitBox }
RP.FilterType = Enum.RaycastFilterType.Exclude
RP.FilterDescendantsInstances = FilterDescendantsInstances
while true do
local RayDirection = {
Part.CFrame.LookVector,
-Part.CFrame.LookVector,
Part.CFrame.RightVector,
-Part.CFrame.RightVector
}
HitBox.Anchored = true
for i, v in pairs(RayDirection) do
local Raycast = workspace:Raycast(Part.Position, v * 20, RP)
if Raycast then
local Distance = (Part.Position - Raycast.Position).Magnitude
HitBox.CanCollide = false
HitBox.Position = Part.Position
HitBox.Size = Vector3.new(1, 1, Distance)
HitBox.CFrame = CFrame.new(Part.Position+(RayDirection[i] * (Distance/2)), Raycast.Instance.Position)
HitBox.Parent = workspace
print(Raycast.Instance)
end
end
wait(0.250)
end

I see. Sorry, I don’t know if that’s possible or reasonable. Are you using the ray cast to lock on to a player? Otherwise you might be better off just using (Part.Position - playerHumanoidRootPart.Position).Magnitude

Yes indeed. For raycasts though, I would do is this:

for i = 1,360 do
local x,z = math.sin(math.rad(i)),math.cos(math.rad(i)) -- I made vectors from angles using sin and cosine.
local ray = workspace:RayCast(Position,Vector3.new(x,0,z)*8,RP) -- Then I apply.
end

local RayDirection ={}
HitBox.Anchored = true
for i = 1, 24 do
local RNG = Vector3.new(math.random(0, 360), 4, math.random(0, 360))
table.insert(RayDirection, RNG)
end

raycasting can be expensive, doing that is bad practice, better methood is using bounding box, then if it will detect any object shoot one ray to it to check if there’s any obstacle, you can use magnitude too