function round(number, to)
to = to or 1
return math.floor(number/to + 0.5) * to
end
function roundVector(vector, unit)
return Vector3.new(round(vector.X, unit), 7--[[vector.Y]], round(vector.Z, unit))
end
local renderStepped = runService.RenderStepped:Connect(function()
if not startedPlacingWall then
local mouseP = mouse.Hit.p
pole1.CFrame = CFrame.new(roundVector(mouseP + Vector3.new(0, pole1.Size.X/2, 0), gridSize))*CFrame.Angles(0, 0, math.rad(90))
else
renderStepped:Disconnect()
end
end)
I’m trying to prevent this part from going outside of the players base plate. Atm they can move there mouse anywhere and the part will follow. I’m using the roundVector function to lock it to a 4 stud grid too, not sure if that could be helpful for incorporating that? The base plate is 160x160, but I would like to be able to change that in the future, so if the function could include the base plates size and not default size of 160x160.