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

How would I make a bigger grid to snap to?

So I managed to create a basic grid system where you move an object (Part or Model) to each stud. This is working but I want to know how to add to the grid. Instead of it being moved to each stud maybe every 4 or 5 studs.

Here is my code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Part = workspace.Movement.PrimaryPart -- The model that I am moving

Mouse.Move:Connect(function()
	local PosX = math.ceil(Mouse.Hit.X) -- I also used math.floor()
	local PosY = 11.1 -- The current y position of the model's primaryPart
	local PosZ = math.ceil(Mouse.Hit.Z) -- I also used math.floor()
	
	-- Moving the model
	Part.Parent:MoveTo(Vector3.new(PosX, PosY, PosZ))
end)

I have tried added values to the Pos variables (lines 6-8) and it just creates a bigger problem. Thanks to who helps me!

1 answer

✓ Accepted answer

You just need to round a little differently. It's basically the same as rounding the nearest multiple of 10.

local num = 17
local step = 10

print(math.floor(num / step + .5) * step)
--20

The logic for a different step is exactly the same, just divide, round, multiply.

1 comment

0

Thanks

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