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

how to make math.floor round to the nearest 5, not the nearest 1?

i don't really know how to word this. I'm making a grid placing system, where a part follows your mouse, when you click, it stops following your mouse. it want it to move on a grid of 5, but have no idea how to do it. the closest i've gotten is math.floor, but that only rounds to the nearest whole number, making it a grid of 1. (not filtering enabled, just testing) localscript inside of screengui:

local button = script.Parent.TextButton
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local click = false
button.MouseButton1Click:Connect(function()
	if click == false
		then click = true
	end
local floor = Instance.new("Part", workspace)
floor.Size = Vector3.new(5,.1,5)
floor.Anchored = true
mouse.Button1Down:Connect(function()
	if click == true then
		click = false
	end
end)
repeat
local posx, posy, posz = mouse.Hit.X , mouse.Hit.Y, mouse.Hit.Z
	floor.Position = Vector3.new(math.floor(posx),0,math.floor(posz))
	wait()
until click == false

end)

1 answer

Use the modulus "%". Modulus is like division, but returns the remainder. 11 % 5 would return as "1", because 10 splits into 5 equally with 1 left over. Use this with a loop and you could find a rounded number that rounds to 5.

2 comments

0

so.. how would i implement this into math.floor?

0

You cant. Math.floor floors a number. It doesn't round it. It just cuts off the decimal place from a number.

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