Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
wookey12 174
6 years ago

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

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

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.

0
so.. how would i implement this into math.floor? wookey12 174 — 6y
0
You cant. Math.floor floors a number. It doesn't round it. It just cuts off the decimal place from a number. H4X0MSYT 536 — 6y
Ad

Answer this question