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

How do I convert mouse.Hit to a position on the workspace?

Asked by 7 years ago
mouse.Button1Down:connect(function()
    local target = mouse.Target
    if target:IsA("Part") and target.Name == "BuildingMaterial" then
        target.Position = mouse.Hit
    end
end)

ERROR: 21:16:12.452 - Players.Player1.Backpack.Build.LocalScript:43: bad argument #3 to 'Position' (Vector3 expected, got CFrame)

All help is appreciated :)

1 answer

Log in to vote
0
Answered by 7 years ago

Alright so.

target.Position = mouse.Hit

There is an issue with this part. mouse.Hit is a CFrame(CoordinateFrame) while Position is a Vector CFrame has a ".p" property, which is the Vector of the CFrame.

if you simply switch

target.Position = mouse.Hit

to

target.Position = mouse.Hit.p

It'll work fine, since you're setting Vector to Vector and not Vector to CFrame

Ad

Answer this question