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

How to place a block perfectly next to another block?

Hello, I made two scripts where you can place blocks around the world (or something) and stalked with one problem. You can't perfectly place a block next to another block. In my opinion, it creates big trouble. How can I solve it? Here are these scripts: (The placement aside which I tried to make, is located in the local script, mouse.Move function)

Local Script:

local tool = script.Parent
local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("BuildEvent")
local block

local rotation = 0

local createBlock = function()
	local newblock = Instance.new("Part", workspace:WaitForChild("Folder"))
	newblock.Size = Vector3.new(4,4,4)
	newblock.Anchored = true
	newblock.CanCollide = false
	newblock.Transparency = .5
	newblock.Name = "Block"..math.floor(math.random())
	return newblock
end

tool.Equipped:connect(function(mouse)
	block = createBlock()
	mouse.Button1Down:connect(function()
		if mouse.Target then
			event:FireServer(block.Position)
		end
	end)
	mouse.Move:connect(function()
		wait()
		if mouse.Target then
			mouse.TargetFilter = block
			if mouse.Target.CFrame.LookVector then
				block.CFrame = CFrame.new(mouse.Target.Position) + Vector3.new(4,0,0)
			elseif (-1 * mouse.Target.CFrame.LookVector) then
				block.CFrame = CFrame.new(mouse.Target.Position) - Vector3.new(4,0,0)
			end
			if mouse.Target.CFrame.UpVector then
				block.CFrame = CFrame.new(mouse.Target.Position) + Vector3.new(0,4,0)
			elseif (-1 * mouse.Target.CFrame.UpVector) then
				block.CFrame = CFrame.new(mouse.Target.Position) - Vector3.new(0,4,0)
			end
			if mouse.Target.CFrame.RightVector then
				block.CFrame = CFrame.new(mouse.Target.Position) + Vector3.new(0,0,4)
			elseif (-1 * mouse.Target.CFrame.RightVector) then
				block.CFrame = CFrame.new(mouse.Target.Position) - Vector3.new(0,0,4)
			end
		end
	end)
end)

tool.Unequipped:connect(function()
	block:Destroy()
end)

(Server) Script:

local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("BuildEvent")

event.OnServerEvent:connect(function(player, pos)
	local newblock = Instance.new("Part", workspace:WaitForChild("Folder"))
	newblock.Size = Vector3.new(4,4,4)
	newblock.Anchored = true
	newblock.Name = "Block"..math.floor(math.random())
	newblock.CFrame = CFrame.new(pos)
end)

Thanks in advance.

1 answer

✓ Accepted answer

Simple! Change the moving increment with a script

The moving increment is often used as rotating or moving Parts smoothly. Similar to Tween-service and Lerping but it does not run in game.

Search "Moving Increment Roblox Studio" in YouTube and you will probably find some better results

If there are any errors, please comment

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