How to move a model

I already explained that situation

I know, :PivotTo() more performant than :SetPrimaryPartCFrame() but it may also solve the issue.

local part = workspace.Model
local part2 = workspace.Whatever
local offset = Vector3.new() -- Keep it how much far you want your model to be from the other block

--whenever you want to detect
local parts = part.PrimaryPart:GetTouchingParts()
for i,v in pairs(parts) do
if v.Name = part2.Name then
part:PivotTo(CFrame.new(part2.Size + offset))
end
end

You can’t really overlap things if they can collide, because collide just means that they can’t overlap.

Now, you can turn off CanCollide of both the parts, then if your model touches the part you want, move it by offset.

PivotTo() also doesn’t let the parts overlap. I’ll try pivotTo() on the primary part instead of the model.

Hey guys, this peice of code worked for me :slight_smile:

local model = Instance.new("Model",workspace)
local prim = Instance.new("Part",workspace)
prim.Position = Vector3.new(10,10,10)
prim.Anchored = true
prim.CanCollide = true
model.PrimaryPart = prim
local part = Instance.new("Part",workspace)
part.Anchored = true
part.CanCollide = true
part.Position = Vector3.new(0,0,0)
part.Size = Vector3.new(10,10,10)
model.PrimaryPart:PivotTo(Vector3.new(0,0,0))

It moved the model to thee desired location, and it overlapped! :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.