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)
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.