How to round numbers in pairs of 2 like 2, 4, 6, 8

I wanted to make a grid building system that can place a item every 2 studs, to make the player unable to place a block anywhere in between.

robloxapp-20220726-2225381.wmv (161.6 KB)

But I don’t know how to round a number in pairs of two

math.round doesn’t work because it only rounds to wholes. I also tried to make a function that loops through the number to find how many pairs of two there are but that wouldn’t work with negative numbers.

local function RoundInPairs(Pair, number)
	local Count = 0
	while number > Pair do
		Count = Count + 2
		number = number - 2
	end
	return Count
end

You can divide number by 2, math.round() it and then multiply it by 2 back

3 Likes

You can use mod/%:

if number % 2 == 0 then
...
end
1 Like