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

How do I make the block go into the correct place? [SOLVED]

I'm building a Minecraft Spin-off for Roblox, and I have a working 4-block grid placement system, but most of the time the blocks are off by one snapping point. Although it depends on where on the block you tap, click, it sometimes, only sometimes goes to the incorrect block. Here's a snippet of code showing the build function. All of the building controls are binded to the function.

local function build()
	local x = mouse.Hit.p.X
	local y = mouse.Hit.p.Y
	local z = mouse.Hit.p.Z
	
	x = (round(x/4) * 4)
	y = (round(y/4) * 4)
	z = (round(z/4) * 4)
	
	local position = Vector3.new(x + 2, y + 2, z + 2)
	
	local part = Instance.new("Part", workspace)
	part.Size = Vector3.new(4,4,4)
	part.Position = position
	part.Anchored = true
	if material.Value == 1 then
		part.Material = Enum.Material.WoodPlanks
		part.BrickColor = BrickColor.new(38)
	elseif material.Value == 2 then
		part.Material = Enum.Material.Brick
		part.BrickColor = BrickColor.Red()
	elseif material.Value == 2 then
		part.Material = Enum.Material.Cobblestone
		part.BrickColor = BrickColor.Gray()
	end
end

Help would be appreciated. Thank you!

2 answers

Kinda easy Basically just

Just make all those 2s on line 10 1

So it would be

local position = Vector3.new(x + 1, y + 1, z + 1)

2 comments

0

That wouldn't work, since each of my blocks are 4 x 4 x 4 studs

0

Ah.

I fixed it by making the original click position offsetted by 2, then after rounding subtracting 2, and it fixed it.

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