So I’m trying to make a script that fires a Raycast down from 20 studs behind the player, then I want to set a part position or cframe to that Raycast.Position.
I can’t figure out how to set the RayOrigin in the Z value to always be 20 studs behind the location that the player is facing.
local function behindplayer()
local randomplr = selectPlayer()
local char = randomplr.Character
local hrpcframe = char:FindFirstChild("HumanoidRootPart").CFrame
local hrppos = hrpcframe.Position
local rayOrigin = hrpcframe.Position + Vector3.new(0,100, hrpcframe * 10) -- Here is the issue!
local rayDirection = Vector3.new(0,-200,0)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if raycastResult ~= nil then
npc.PrimaryPart.CFrame = CFrame.new(raycastResult.Position)
print("Setting location!")
end
end
All Help is appreciated!