still printing nil, with both of your guys’ solutions.
Could you try like creating a new part and setting its position to the rayOrigin to check if its even on the right place? Also if the raycast aims always down, change the rayDirection to just Vector3.New(0,-1,0)
It’s still returning nil wil the 0,-1,0
Just one more check to be completely sure, make the rayDirection in the raycast *200, because just *10 could maybe not be enough when I now look on where the origin is compared to the terrain
still printing nil
local rayOrigin = Vector3.new(part.Position.X + math.random(-part.Size.X/2, part.Size.X/2) ,part.Position.Y + part.Size.Y , part.Position.Z + math.random(-part.Size.Z/2, part.Size.Z/2))
local rayDirection = Vector3.new(0,-200,0)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Include
raycastParams.FilterDescendantsInstances = {workspace.Terrain}
--raycastParams.RespectCanCollide = false
local raycastResult = workspace:Raycast(rayOrigin, rayDirection.Unit * 10, raycastParams)
print(raycastResult)
I meant this to multiply by 200 instead of the 10
Ahh, still giving the nil result.
While, doing Vector3.new(0, -xxx, 0)
works you’d still need to make sure the distance of the vector is long enough. Also, might be a dumb question but is the terrain Roblox’s Terrain or custom terrain? (only reason I’d ask is because if it’s custom that might be the reason why workspace.Terrain isn’t working as it should)
Minor detail:
Plus, your origin from the code you sent is still above the part, not on the top.
local rayOrigin = Vector3.new(
math.random(-part.Size.X/2, part.Size.X/2),
part.Size.Y * .5,
math.random(-part.Size.Z/2, part.Size.Z/2)
) + part.Position
local rayDirection = Vector3.new(0, -5000, 0) -- // Max distance
It is roblox terrain. I think that has something to do with it, because when I remove it stops printing as nil but the issue is it doesn’t detect terrain still.
I’m just going to make custom attachments and have it randomly pick one at this point, idk why roblox has made this so difficult to do. Thanks for the help.
I take back what I said, apparently even removing the workspace.terrain still has the nil problem.
From the code you provided, it looks like you’re using a Raycast to detect when the ray hits terrain. You’ve also set up a blacklist for materials that you don’t want to trigger the event. However, it’s not clear from the code why parts are spawning in random air and all over the place below.
Have you tried debugging your code to see what might be causing this issue?
They are spawned to test if it was working correctly. Yes, however the rays are firing from the correct origin, but as a result they just return “nil”.