How to move a model to a CFrame?

Hello, how can I move a model without using PrimaryPartCFrame, moving all the parts to the position

function PlaceObjectAt(x,y)
		local CalculateCFrame = CFrame.new()
		y.CFrame = CalculateCFrame
end

local objects = {}

for i,v in ipairs(workspace.Crate:GetChildren()) do			
	objects[v] = false																																																								
	v.Moving.ClickDetector.MouseClick:Connect(function()
	if objects[v] == false then
		objects[v] = true --Primary
		v.Moving.ClickDetector.Open:Play()
		v.Moving.Primary.Motor.MaxVelocity = 0.03
		v.Moving.Primary.Motor.DesiredAngle = -1.05
		v.Moving.Particle.Sparkles.Enabled = false
		local object = game.ReplicatedStorage.Weapons:FindFirstChild(SetupCrates()):Clone()
		object.Parent = workspace.Crate.Model.CurrentWeapon
		for index,a in ipairs(object:GetChildren()) do
          PlaceObjectAt(v.GunSpawn, a)
		end
	elseif objects[v] == true then
		objects[v] = false
		v.Moving.Primary.Motor.MaxVelocity = 0.03
		v.Moving.Primary.Motor.DesiredAngle = 0
	end
end)
end

So my attempt was PlaceObjectAt()
How can I move the model part cframe to the X Cframe without making it loose it’s form
What I mean without using it form: image

1 Like

If you don’t want to use “:SetPrymaryPartCFrame()” then you can use “:MoveTo()”

3 Likes

Ohhh I though :MoveTo() was only for humanoid…

1 Like

Oh it’s ok. Now you know something new pal.

1 Like

The :MoveTo() method doesn’t tween. It will move the model instantly to the desired Position. See Introduction to Tweening Models for information on how to accomplish that.

Yes I know, but I tweened so ignore it :slight_smile: thx anyway

You could…

local function offsetModel(model, offset)
    for _, desc in ipairs(model:GetDescendants()) do
        if desc:IsA('BasePart') then
            desc.CFrame = offset * desc.CFrame
        end
    end
end

local function moveModel(model, cframe)
    local current = model:GetBoundingBox()
    local offset = current:ToObjectSpace(cframe)
    offsetModel(model, offset)
end
2 Likes