Issues with raycasting

Hello everyone,

I’m trying to use a raycast for an ability. However, the script doesn’t raycast correctly and I’m not sure why.

script:

local HumanoidRootPart = player.Character.HumanoidRootPart
local HitPosition = HumanoidRootPart.Position + (HumanoidRootPart.CFrame.LookVector * 20)
local PositionRayCast = workspace:Raycast(HitPosition,HitPosition - Vector3.new(0,10,0))

local Part = Instance.new("Part")
Part.Size = Vector3.new(1,1,1)
Part.Position = PositionRayCast.Instance.Position
Part.BrickColor = BrickColor.new("Really red")
Part.Material = Enum.Material.Neon
Part.Name = "HitPart"
Part.Parent = workspace
Part.Anchored = true
Part:Clone().Parent = workspace

what I’m trying to do is put a part infront of the player and then raycast underneth the part to check for any ground but the raycast doesn’t go downward.

Thank you

  1. How is it not raycasting correctly?
  2. You’re assuming that the raycast hits something, even though it might not.
  3. Your script will run only once. I’m not sure if that it is what you want.
  1. it doesn’t raycast downward
  2. there is more to the script but this is the “broken” part the other parts are not needed
  3. that’s what I want it to do

To raycast down, replace this line:

local PositionRayCast = workspace:Raycast(HitPosition,HitPosition - Vector3.new(0,10,0))

With this:

local PositionRayCast = workspace:Raycast(HitPosition,Vector3.new(0, -10, 0)) -- change -10 to whatever distance you want
1 Like