Hi, lately I’ve been trying to make a building system that snaps to 5 studs. I’ve achieved this quite fine with no bugs but the only problem is is that the blocks wont stack on top of each other. You can kind of think of my building system as it would be in minecraft. I can stack up 2 blocks but then they just start going into eachother and it’s a mess. I’m not sure how to fix this so I came here for answers, here’s my code:
(I also believe that the issue is around where it says PosX PosY and PosZ as that’s where it snaps to a grid.)
mouse.Move:Connect(function()
local mouseRay = mouse.UnitRay
local rayCastParams = RaycastParams.new()
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
rayCastParams.FilterDescendantsInstances = {GhostItem, player.Character}
local castRay = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 500, rayCastParams)
local ignoreList = {GhostItem, player.Character}
if castRay and castRay.Instance:IsA("BasePart") and math.floor((humRootPart.Position - castRay.Position).Magnitude) <= 20 then
CanPlace = true
for i,v in pairs(GhostItem:GetChildren()) do
v.BrickColor = BrickColor.new("Bright green")
end
local PosX = math.floor(castRay.Position.X / GridSize) * GridSize
local PosY = GhostItem.PrimaryPart.Position.Y
local PosZ = math.floor(castRay.Position.Z / GridSize) * GridSize
GhostItem:SetPrimaryPartCFrame(CFrame.new(PosX,PosY,PosZ))
else
CanPlace = false
for i,v in pairs(GhostItem:GetChildren()) do
v.BrickColor = BrickColor.new("Really red")
end
end
end)
Note that I cut out most of the code because it’s just variables and what not, I also feel like this itself is a big chunk of code to read and attempt to fix let alone 40+ other lines.