Ok so originally I was using this to snap my part to a grid
local PosX
local PosY
local PosZ
local GridSize = 2
function Snap(mouse, model)
PosX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize
PosY = model.PrimaryPart.Position.Y
PosZ = math.floor(mouse.Hit.Z / GridSize + 0.5) * GridSize
return PosX, PosY, PosZ
end
Model:SetPrimaryPartCFrame(CFrame.new(PosX, PosY, PosZ) * CFrame.Angles(0, math.rad(Rotation), 0))
Now this code worked, but problem with it was that I couldn’t place the model on walls or it would be go in between walls.
So now I want to use this code as it works on placing the object on the walls, etc. Code from this post Placement System For Wall Objects - #9 by Imaginze
local UnitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y, 1)
local NewRay = Ray.new(UnitRay.Origin, UnitRay.Direction * 1000)
local Hit, Pos, Normal = workspace:FindPartOnRay(NewRay, Model)
Model:SetPrimaryPartCFrame(CFrame.new(Pos, Pos + Normal * 15) * CFrame.Angles(-math.rad(90), math.rad(Rotation), 0) * CFrame.new(0, Model.PrimaryPart.Size.Y / 2, 0))
Problem with this code however is that it doesn’t snap to a grid
Can anyone help with incorporate my original code with this new code?