I’m assuming what you mean is when you’re attempting to create a part, it doesn’t line up like so:
Please correct me if I’m wrong.
I’ve taken your code and tried it out on a baseplate world, and I can see that the object doesn’t line up, and instead is off by a couple pixels. Can you make sure that your 100 by 100 block that people can place objects on is perfectly aligned to the stud grid?
If that doesn’t work, you can try replacing goal.Position = Vector3.new(...)
in your code with this:
local Y_OFFSET = 1.5
local PLACEMENT_OFFSET = 0
local relativePosition = Vector3.new(mouse.hit.Position.X,0,mouse.hit.Position.Z) - workspace.Part.Position
relativePosition = Vector3.new(math.floor(relativePosition.X), Y_OFFSET, math.floor(relativePosition.Z))
goal.Position = workspace.Part.Position + relativePosition + Vector3.new(PLACEMENT_OFFSET, 0, PLACEMENT_OFFSET)
Allow me to explain
To make this easier, I’ll be calling the part you want to place furniture and the part that you’re placing it on ground.
This script first gets the position of the furniture relative to the ground. Using that value we can then round and not be screwed over by the world grid.Then, we take that value and add it back onto the ground in order to get the offset position, and add on PLACEMENT_OFFSET
in case we want to change it later.
Y_OFFSET
is how far you want the object to be from your 100 by 100 part in the Y axis. If the part is instead half a stud off, you can change PLACEMENT_OFFSET
to 0.5
.
On an off note, you might want to consider making the function in mouse.Move:Connect()
non-anonymous so you can update the position of the furniture when you move around as well.
Cheers!
EDIT In any case, this tutorial might be of use, as it’s really informative and easy to follow.