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

2 comments
didnt expect anyone to answer, im currently trying out a solution, if it doesnt work then im gonna try yours
nope didnt rly work