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

Brick Placement On A Stud Grid?

So here is a script I sort of modified and I want to know how to make the bricks be placed on a 1 stud instead of using no grid. Below is the script.

tool = script.Parent

function click(mouse)
	local part = Instance.new("Part")
	part.Position = mouse.hit.p
	part.Parent = game.Workspace
	part.Anchored = true
end

function selected(mouse)
	mouse.Button1Down:connect(function () click(mouse) end)
end

tool.Selected:connect(selected)

1 answer

✓ Accepted answer

ill try to explain the best I can! Reply if you need me to clear something up.

So the basics behind what you want to do is simple! Lets say hypothetically that mouse.Hit.p == 0.1, 0.5, 0.9

Knowing that math.floor( NUMBER ) returns NUMBER rounded down, always down.

So if you took each offset value of mouse.Hit.p and added 0.5 to it, then round it down. You would have the closest whole number.

Local Pos = Vector3.new( math.floor(mouse.Hit.p.X + 0.5),math.floor(mouse.Hit.p.Y + 0.5),math.floor(mouse.Hit.p.Z + 0.5)) -- as an example 

6 comments

0

When you say Pos, does that refer to position?

0

Never mind! I got it working! Thank you for the help!

0

How would I change the X and Z grid to 2 studs?

0

I believe you would divide the position of the mouse by 2, add 0.5 again (because it rounds down automatically), then multiply that by 2 again!

0

I did it but all it does is offset where the brick is placed. Here is what I wrote: local Pos = Vector3.new( math.floor( mouse.Hit.p.X /2+0.52),math.floor(mouse.Hit.p.Y + 0.5),math.floor(mouse.Hit.p.Z /2+0.52))

0

you haveto remeber BEDMAS Brackets,exponents,division,multiplication,addition subtraction. (mouse.Hit.p.X /2+0.5*2) should be ((mouse.Hit.p.X /2+0.5)*2)

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