Difference between Mouse.Target and MouseRaycast

Hello devs, I have always wondered what is the difference between MouseRaycast and Mouse.Target? Since you can get materials, instances, colours, from both of them. I saw a lot of people use MouseRaycast and Mouse.Target. MouseRaycast is a function.

local UserInputService = game:GetService("UserInputService")

local camera = workspace.CurrentCamera

local function MouseRaycast()
	local mousePosition = UserInputService:GetMouseLocation()

	local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)

	local raycastResult = workspace:Raycast(mouseRay.Origin,mouseRay.Direction * 1000)
	return raycastResult

So, what’s the difference between both of these Mouse.Target and MouseRaycast?

TL;DR there’s probably no difference, MouseRaycast is just the use of newer API.

While I’m not sure about the information that Mouse.Target provides, Mouse is legacy, on the documentation for it it says:

Mouse has been superseded by UserInputService and ContextActionService, which cover a broader scope, are more feature rich, and support cross-platform patterns better. It remains supported because of its widespread use, but you should strongly consider using these alternatives.

So I think MouseRaycast is just a way to use the newer technologies or whatnot, though I’m sure Mouse.Target will still work fine for a lot of use-cases.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.