Get the position the mouse is pointing at

So on my voxel game i needed a way to destroy blocks the game is in first person so i need a way
to get the position that the mouse is pointing is there an efficient way to do this?

Since the mouse is 2d i would like a way for it to convert to 3d

1 Like

You can access the 3D position the mouse is pointing at locally.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

print("Mouse position is " .. Mouse.Hit.p)

Read more on Mouse.Hit in @nicemike40 post above.

Using this information, you can use rays to check if its clicking on a block.

If you want to check if the mouse is clicking on an object you can do this to retrieve the selected object:

local target = Mouse.Target

Note: if there is nothing the mouse is pointing out, target would be nil. Read more on Mouse.Target here.