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

Rounding/Snaping to grid X, Y and Z Putting part on top of clicked part?

--Server Script FE Enabled
--x is mouse.hit.x, y is mouse.hit.y and z is mouse.hit.z the mouse hits are sent from the player with a remote event
local function roundXYZ(x,y,z)
	return Vector3.new(x-x%3,y-y%3,z-z%3)
end
cl.Position = roundXYZ(posX,posY,posZ)

Why is this script not placing the part on side of another part when i click on the side and instead on top of the clicked object?

2 comments

0

One problem could be that you're using Position instead of CFrame

0

ok

1 answer

local function roundXYZ(x,y,z)
	local cframe = CFrame.new(x-x%3,y-y%3,z-z%3)
	local surface = mouse.TargetSurface
	if surface == Enum.NormalId.Right then
		cframe = cframe * CFrame.new(3, 0, 0)
	elseif surface == Enum.NormalId.Left then
		cframe = cframe * CFrame.new(-3, 0, 0)
	elseif surface == Enum.NormalId.Top then
		cframe = cframe * CFrame.new(0, 3, 0)
	elseif surface == Enum.NormalId.Bottom then
		cframe = cframe * CFrame.new(0, -3, 0)
	elseif surface == Enum.NormalId.Front then
		cframe = cframe * CFrame.new(0, 0, -3)
	elseif surface == Enum.NormalId.Back then
		cframe = cframe * CFrame.new(0, 0, 3)
	end
	return cframe
end
cl.CFrame = roundXYZ(posX,posY,posZ)

2 comments

0

did not work :/

0

Is the original object the same size as the other one?

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