How would I make a script that gets the mouse position In 3d without using a tool?

i have been making a game and a function of the game is placing items and to do so I need the players mouse position how would I get the 3d mouse position?

There’s a property for this:

https://developer.roblox.com/en-us/api-reference/property/Mouse/Hit

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

while true do
	task.wait()
	print(Mouse.Hit.Position)
end
1 Like

is that the 3d position of the cursor???

I have a slingshot tool in my game. Here is a function I use for the 3d mouse location. Hope this helps!

--this is a local script
local player = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")

local function getMouseLocation()
	local mousePosition = userInputService:GetMouseLocation()
	local x = mousePosition.X
	local y = mousePosition.Y

	local unitray = workspace.CurrentCamera:ViewportPointToRay(x, y, 0)
	local ray = Ray.new(unitray.Origin, unitray.Direction * 1000)
	local target, position = workspace:FindPartOnRayWithIgnoreList(ray, {player.Character})

	return position
end