Greetings, Developers.
I am attempting to make a gun engine and I am running into an error at the minute while trying to cast a ray.
I have just modified my Raycast from the below:
local player = LocalPlayer
local position = cursor.Hit.Position
local LocalPlr = Workspace:FindFirstChild(LocalPlayer.Name)
local rayOrigin = LocalPlr.Head.Position
local bulletOrigin = shoot_part.Position
local direction = (position - rayOrigin).Unit*300
local result = Workspace:Raycast(rayOrigin, direction)
To this:
local player = LocalPlayer
local position = cursor.Hit.Position
local LocalPlr = Workspace:FindFirstChild(LocalPlayer.Name)
local rayOrigin = LocalPlr.Head.Position
local bulletOrigin = shoot_part.Position
local direction = (position - rayOrigin).Unit*300
print(direction)
local headRay = Ray.new(rayOrigin, direction)
local result = Workspace:FindPartOnRayWithIgnoreList(bulletOrigin, LocalPlr)
local wallcheck = Workspace:FindPartOnRayWithIgnoreList(rayOrigin, LocalPlr) --Added to determine if player is trying to shoot through a wall.
I did this so that I can successfully ignore the player whenever the ray casts as the user can damage themselves whenever firing, however now I am running into an issue now I am using FindPartOnRay as opposed to Raycast.
I am not sure exactly what I have done wrong when I switched from Raycast to FindPartOnRay so any help is appreciated!
Thank you!
Edit
I forgot to post the console error.
14:53:22.017 Unable to cast Vector3 to Ray - Client - WeaponMain:41
(WeaponMain:41 refers to “local result =…”)
