long story short im creating a grid placement system with snapping into place, but it only snaps if the part size is even (for example 2x2x2). if its not even then it snaps between the grids. i have tried adding half a stud to the part so its in the right place but it didnt work well. here is the script and an image:
local module = {} module.place = function(plr,item) local blacklist = {} for i,v in pairs(item.Parts:GetChildren()) do table.insert(blacklist,v) end local mouse = plr:GetMouse() local function snapToGrid(vector3,middle,folder) local x = math.floor(vector3.X+0.5) local y = math.floor(vector3.Y+0.5) local z = math.floor(vector3.Z+0.5) folder.Parts:MoveTo(middle+Vector3.new(-x,y + folder.Parts.PrimaryPart.Size.Y/2,-z)) end local hitbox = item.Parts.PrimaryPart local RS = game:GetService("RunService") local maxHeight = 250 local plot for i,v in pairs(game.Workspace.Plots:GetChildren()) do if v.Owner.Value == plr.Name then plot = v for i,b in pairs(v.BaseParts:GetChildren()) do b.Grid.Transparency = 0 end end end item.Parent = workspace.Placing RS.RenderStepped:connect(function() local ray = Ray.new(mouse.UnitRay.Origin,mouse.UnitRay.Direction*1000) local hit, mousepos = game.Workspace:FindPartOnRayWithIgnoreList(ray, blacklist) local pos = plot.BaseParts.BasePart1.Position - mousepos if hit then snapToGrid(pos,plot.BaseParts.BasePart1.Position,item) end wait() end) end return module
http://prntscr.com/xihm1t
That is just how grids work. The solution will always require some trade-off. Basically you have four options.
local xAdjust = folder.Parts.PrimaryPart.Size.X % 2 -- the remainder of division local yAdjust = folder.Parts.PrimaryPart.Size.Y / 2 local zAdjust = folder.Parts.PrimaryPart.Size.Z % 2 folder.Parts:MoveTo(middle+Vector3.new(-x + xAdjust,y + yAdjust, -z + zAdjust))
I hope this helps.