Increments with Parts

I know how to make a script where a part displays wherever you move your mouse. Here’s an example;

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local part = Instance.new(“Part”)

part.Anchored = true

game:GetService(“RunService”).RenderStepped:Connect(function()

part.Parent = workspace

part.Position = Vector3.new(mouse.hit.p.X,0,mouse.hit.p.Z)

end)

I’d like some help on how I can use an increment on the part so it moves 1 stud at a time rather than .001 studs (which would turn out uneven)

If that doesnt make any sense just picture using the drag tool from roblox I want the part to automatically snap onto another part with a 1 stud increment. How do I go about with doing this?

2 Likes

The has been a similar post here.

1 Like

Ah appreciate it also do you know what i’d do to snap the part onto a baseplate so it isn’t inside of it partially?

You can force it up,

-- i assume its half way in
local function brickup(pos,size)
    return position+Vector3.new(0,size.Y/2,0)
end

-- in main
part.Position = brickup(mouse.Hit.p,part.Size)

Also,

You don’t need to set the parent to workspace every renderstepped, only once.

It’s even simpler than this, don’t work harder if you don’t need to. Use the math.ceil() function, it automatically rounds up so instead of 0.1, you have 1, and so on and so forth. Version that I tested:

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local part = Instance.new(“Part”)

part.Anchored = true

game:GetService(“RunService”).RenderStepped:Connect(function()

part.Parent = workspace

part.Position = Vector3.new(math.ceil(mouse.hit.p.X),0,math.ceil(mouse.hit.p.Z))

end)

1 Like