Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.