I have a raycast script that creates a raycast, then checks if the raycast hits a part that contains a humanoid.
However, I keep getting this error: Unable to cast RaycastResult to Ray
I’m not really good at raycasting so i don’t know how to fix this. Can someone help please?
local params = RaycastParams.new()
local direction = currentNormal*(overrideDistance or stepDistance)
params.FilterDescendantsInstances = {script.Parent.Parent}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = game.Workspace:Raycast(currentPos,direction,params)
local pos
if result then
print(result)
local hit = game.Workspace:FindPartOnRay(result,chr) -- Error occurs here
-- "Unable to cast RaycastResult to Ray'
local hum = hit.Parent:FindFirstChild('Humanoid')
if hum then
hum:TakeDamage(30)
end
end