Hello!
I was wondering how I could make a placement system with a single part for the player’s plot instead of having parts for each grid increment? I currently want a 40x40 grid of 2.5x2.5 stud wide squares, however having 1,600 parts is really inefficient.
Here’s my current placement system for walls, which places them at the edge of each part:
function module:SnapToGrid(mouse, model, testing)
local targ = mouse.Target
if targ then
if model then
if string.find(targ.Name, 'GRID_PART') then
model.Parent = targ
else
return
end
if model:FindFirstChild('Type').Value == 'Wall' then
for i,v in pairs(model:GetDescendants()) do
if v:IsA('BasePart') then
v.Transparency = 0.5
v.CanCollide = false
end
end
local walls = {
wallN = Vector3.new(targ.Position.X + (targ.Size.X / 2), targ.Position.Y, targ.Position.Z);
wallE = Vector3.new(targ.Position.X, targ.Position.Y, targ.Position.Z + (targ.Size.Z / 2));
wallS = Vector3.new(targ.Position.X - (targ.Size.Z / 2), targ.Position.Y, targ.Position.Z);
wallW = Vector3.new(targ.Position.X, targ.Position.Y, targ.Position.Z - (targ.Size.Z / 2))
}
local smallest = Vector3.new(math.huge, math.huge, math.huge)
local smallestWall = ''
local smallestMagnitude = math.huge
for i,v in pairs(walls) do
local testingMagnitude = (v - mouse.Hit.Position).Magnitude
if testingMagnitude < smallestMagnitude then
smallestMagnitude = testingMagnitude
smallest = v
smallestWall = tostring(i)
end
end
local smallestVector = smallest + Vector3.new(0, smallest.Y + (model.PrimaryPart.Size.Y / 2), 0)
if not string.find(targ.Name, 'GRID') then
return
end
local cframe = CFrame.new(smallestVector)
if smallest == walls.wallN or smallest == walls.wallS then
cframe = CFrame.new(smallestVector) * CFrame.Angles(0, math.rad(90), 0)
end
model:SetPrimaryPartCFrame(cframe)
end
end
end
end