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

How to put part on top of other part/surface?

RS.RenderStepped:Connect(function()
	if toggle == true then
		part.Position = Vector3.new(mouse.Hit.Position.X,mouse.Target.Size.Y+part.Size.Y/2-part.Size.Y,mouse.Hit.Position.Z)
	end
end)

I'm doing some tests to enchant my positioning and cframing, today I tried to do some kind of part placement that places on top of other part but my tries wasn't succesful, it either places on center of part, or places it wrong. I tried this also.

RS.RenderStepped:Connect(function()
	if toggle == true then
		part.Position = Vector3.new(mouse.Hit.Position.X,mouse.Target.Size.Y/2+part.Size.Y-part.Size.Y/2,mouse.Hit.Position.Z)
	end
end)

1 answer

✓ Accepted answer

You would have to use CFrame.UpVector.

I have a hard time understanding CFrame, but UpVector is something you can see as the blue arrow when moving a part. It's basically the up-direction of a part.

There's an example on the Developer wiki of Roblox on how to make a part directly go forward:

cf = cf + cf.LookVector * 5 -- Move cf forward 5 studs

You can make use of that.

mouse.TargetFilter = part

RS.RenderStepped:Connect(function()
	if toggle == true then
		part.CFrame = CFrame.new(mouse.Hit.Position) + mouse.Target.CFrame.UpVector * part.Size.Y / 2 
	end
end)

5 comments

0

ok that does works, but how would I make it work with mouse.Hit.Position.X and Z? it just locks on center of part because of mouse.Target

0

Check edit

0

Vector 3 expected, got number

0

Oh oops, one second!

0

Alright, that should do it!

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