What the script does is it takes the UserInputService's mouse position on screen and then uses it to make a ray pointing from the camera, and then trys to use raycasting, but for some reason it isn't working
function getMouseTarget(mousePos)
local ray = workspace.CurrentCamera:ScreenPointToRay(mousePos.x, mousePos.y, 1000)
return workspace:FindPartOnRay(ray)
end
print(getMouseTarget(game:GetService("UserInputService"):GetMouseLocation())
this prints out nil, Vector3, nil, Enum.Material.Air which means it isn't hitting a block even though I knew it should have hit one. I've also tried running this while the camera had been inside a block.
What I've found on it but doesn't seem to work:
This says it worked they got an answer, but when I tested it in my game and when I tested it in a script builder it didn't work:
This also has an answer in the forum that's almost identical, but also doesn't seem to be working:
http://devforum.roblox.com/t/new-mouse-input-query-methods/41304

2 comments
I've tested the code in Voidacity's Script Builder and in my actual game and for some reason it won't hit objects
mouse.Target. simple as that lol