Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the difference between mouse.hit and mouse.target?

Asked by 7 years ago

I want to make a move tool kind of like the one in Make a cake and feed the giant noob. So I know what 'mouse.target' does but how do I use 'mouse.hit'?

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

The .Hit property of the mouse is the CFrame of what the mouse is pointing at, where as .Target is the BasePart the mouse it pointing at. In other words, mouse.Hit is a CFrame, where as mouse.Target is a basepart or nil.

-- example script: Make Part where you click

-- local script in ReplicatedFirst (Or wherever else LocalScripts run)

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
    local part = Instance.new("Part")
    part.Anchored = true
    part.CanCollide = false
    part.CFrame = mouse.Hit
    part.Parent = workspace
end)
0
`Hit` is simply the projection of the mouse cursor in 3D space, not the CFrame of what the mouse it is looking at. That would imply it points to the center of whatever part is being moused over. Link150 1355 — 7y
Ad

Answer this question