Setting model cframe with terrain normal from raycasting with mouse has weird behavior


I’m attempting to make a simple model placement script.

ModelPlacer.MouseEvent = Mouse.Move:Connect(function()
local mhitp = Mouse.Hit.p;
local r =, mhitp.Y + 0.01, mhitp.Z),, -20, 0) )
local hit, position, normal = workspace:FindPartOnRayWithIgnoreList(r, ignore);
print(hit, position);
if hit ~= nil then
    model:SetPrimaryPartCFrame( +, offset.Y, offset.Z), position + normal) * CFrame.Angles(math.rad(rotation.X), math.rad(rotation.Y), math.rad(rotation.Z)));

The ignore table just contains the model itself.

This code results in this weird thing happening:

It seems like the model just randomly breaks, setting the cframe of every part and putting it to the middle of the model? And when I go off of the terrain, it just disappears. I have no idea why this occurs.

I remember seeing a roblox wiki article a long time ago that accomplishes exactly what I am trying to do, but I just can’t find it anymore.


I believe I just fixed this. I was inconsistent with the position in the SetModelCFrame function. I will test more before replying again to solve this.


Yep, that was the problem.