Mouse.TargetSurface but for raycasting

Hi developers, I am making a building game that has a placement system where you can place things on walls.

My system uses raycasting like this

local hit,pos,normal = workspace:FindPartOnRayWithWhitelist(Ray,Whitelist)

How would I be able to replicate the roblox Mouse.TargetSurface but into my script.
I can’t just use Mouse.TargetSurface because my placement system ignores different things then the Mouse.TargetFilter.

I tried using the “normal” but for some reason it was occuring in world space. Maybe this was because I was using Vector3 and not CFrame?

Thanks
– Trymentinc

I’ve actually done this here: roblox-luau-mouse-target-surface/source.lua at main · nox7/roblox-luau-mouse-target-surface (github.com)

Feel free to take a look and ask questions if need be.

3 Likes