So I'm creating a furniture system for my game but I need the entire model to snap to a grid, I know how to snap just a part to a grid and I tried using that function and a for loop to snap each part to a grid in the model but that made it worse
local tool = script.Parent
local moveEvent
local model = workspace.Chair
function Snap(model)
local Pos=model:GetModelCFrame().p
model:MoveTo(Vector3.new(math.floor(Pos.x),math.floor(Pos.y),math.floor(Pos.z)))
end
tool.Equipped:connect(function(eventMouse)
eventMouse.TargetFilter = model
moveEvent = eventMouse.Move:connect(function()
-- model:MoveTo(eventMouse.Hit.p)
Snap(model)
end)
end)
tool.Unequipped:connect(function()
if moveEvent then
moveEvent:disconnect()
end
end)
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
rotateMod(model, CFrame.Angles(0,math.rad(90),0))
end
end
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)
function rotateMod(mod,rotation)
local center = mod:GetModelCFrame()
local parts ={}
local function scan(parent)
for _,obj in pairs(parent:GetChildren()) do
if (obj:IsA("BasePart")) then
table.insert(parts,obj)
end
scan(obj)
end
end
scan(mod)
for _,part in pairs(parts) do
part.CFrame = (center*rotation*(center:inverse()*part.CFrame))
end
end
17:04:14.698 - Unable to cast double to Vector3 17:04:14.699 - Stack Begin 17:04:14.701 - Script 'Players.Player1.Backpack.Place Chair.Placement', Line 6 - global Snap 17:04:14.701 - Script 'Players.Player1.Backpack.Place Chair.Placement', Line 15 17:04:14.702 - Stack End

6 comments
how would I make the snap 1 stud preferably?
simply making the position whole numbers with math.floor()/math.ceil() will snap by 1 stud. I recently posted an example: https://scriptinghelpers.org/questions/38243/click-to-place-wall-build-preview#40631
but how would that work in a model?
By using MoveTo() rather than setting position.
Well in my updated script I get the same error I fixed my script above to show the current
nvm I got it thank you for your help! :)