Tweening a group

Hey everyone! I am currently working on a product which requires to tween a model, now before you say there is another topic on this. Yes i did see it and when i tried to replicate it, it didn’t work and instead only tweens the primary part (see result gif) znB5zXGv2b
Is there any other method that anyone knows? Please reply for possible solutions.

4 Likes

Could you please give us some code? We can’t do much debugging without it.

1 Like

Sure!

local TweenService = game:GetService("TweenService")

local Panel = script.Parent.Doors
local PanelRoot = Panel.PrimaryPart
local tInfo = TweenInfo.new(3.631, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut, 0, false, 0) -- Let's use all defaults here

--> Welding Script <--
for i,o in pairs(script.Parent.Doors:GetChildren()) do
	local Panel = o
	local Part1 = Panel.PrimaryPart

	for _, Part0 in pairs(Panel:GetChildren()) do
		if Part0:IsA("BasePart") and not (Part0 == Part1) then
			local WeldConstraint = Instance.new("WeldConstraint")
			WeldConstraint.Part0 = Part0
			WeldConstraint.Part1 = Part1
			WeldConstraint.Parent = WeldConstraint.Part0

			Part0.Anchored = false
		end
	end
	Part1.Anchored = true
	Part1.CanCollide = false
end

script.Parent.Value.Changed:Connect(function(val)
	if val == true then
		for i,v in pairs(script.Parent.Doors:GetChildren()) do
			if v.Name == "LeftDoor" then
				local Close = TweenService:Create(v.Frame, tInfo, {Position = v.Frame.Position + Vector3.new(0,0,-3.016)}):Play()
			elseif v.Name == "RightDoor" then
				local Close = TweenService:Create(v.Frame, tInfo, {Position = v.Frame.Position + Vector3.new(0,0,3.016)}):Play()
			end
		end
	else
		for i,v in pairs(script.Parent.Doors:GetChildren()) do
			if v.Name == "LeftDoor" then
				local Close = TweenService:Create(v.Frame, tInfo, {Position = v.Frame.Position + Vector3.new(0,0,3.016)}):Play()
			elseif v.Name == "RightDoor" then
				local Close = TweenService:Create(v.Frame, tInfo, {Position = v.Frame.Position + Vector3.new(0,0,-3.016)}):Play()
			end
		end
	end
end)
1 Like

Looks like those parts were anchored? Try weld them to the primary part too if you haven’t. Unanchor them as well.

Why not try GetDescendants instead of GetChildren?

The way that I go about tweening models, is to have a primary part, and then weld all the other parts to that primary part. Leave the primary part anchored and unanchor the rest of the parts, so that they move, when the primary part moves. Then all you have to do is modify the CFrame of the primary part, and because its welded to every other part in the model, the entire model will move.

2 Likes

The parts are supposed to be Anchored when tweening, however the if you put those other models under the Primary Part you selected it should move too

Use WeldConstraints.
Basically, have a Main part that will move, and Weld all other parts to the Moving one.

Create a Pseudo CFrame value and Tween that.

Then create a .Changed event for the CFrame and apply that to the :SetPrimaryPartCFrame of the model(s)

1 Like

I did that, i anchored the primary part and unanchored all extra stuff

Are you sure that all of the parts are welded to the primary part?

yes, in the script the first few lines are for welding the door

in your case with this door, animations would work a lot better and have much tidier code than tweening (also correct me if im wrong, is also better on performance), if you need any help with rigging the door or any other problem with animation id be happy to help!

You could use Lerp to Tween the PrimaryPart and do
Model:SetPrimaryPartCFrame(CFrame)
This would similiar look to this:

Just have a base part, unanchor everything else and weld those unanchored parts to the one being tweened.

local Can = true
local Open = false



local function openclose(val)
	local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(val),0)
	local start = script.Parent.PrimaryPart.CFrame
	script.Parent.Part.Sound:Play()
	wait(.2)
	for i = 0,1,.1 do
		local cfm = start:lerp(finish,i)
		script.Parent:SetPrimaryPartCFrame(cfm)
		wait()
	end
end

script.Parent.Event.OnServerEvent:connect(function(Player)
	local Mag = (script.Parent.Center.Position-Player.Character.HumanoidRootPart.Position).magnitude
	if Mag <= script.Parent.Range.Value then
		if Can then
			Can = false
			if Open == false then
				openclose(90)
				Open = true
			else
				Open = false
				openclose(-90)
			end
			Can = true
		end
	end
end)

This is how I would create it.

If you’re explicitly using the method in my thread, then it calls for the parts you also want to tween with the PrimaryPart not to be anchored. The principles are as follows:

  • Get a PrimaryPart (or other kind of root) to be the part you tween.
  • Weld all other parts to this root. Everything except the PrimaryPart should be unanchored.
  • It now moves as shown in the videos.

I can’t tell exactly if this is the issue or not but I noticed that you’re modifying the position rather than the CFrame. This shouldn’t be an issue though because of the welds. Will need more information such as the hierarchy of your doors. Are any unwanted joints being created anywhere, are the parts unanchored, etc… make sure to check your environment or re-rig your model.


@OiiTaru @ElectricalSpy SetPrimaryPartCFrame is bad for models expected to move frequently and constantly and I do not encourage its use unless you only need it for brief moments. It does take a few hundred calls but models do tear apart noticeably for models that move around lots.

1 Like

I pulled this off with one of my doors. Why not use WeldConstraints?

I’ll tell you what I did to pull this off. I used a NumberValue to tween instead of the PrimaryPart. As I did that, I had a NumberValue Changed function. The NumberValue’s value is tweened between 0 - 100. Every time, the NumberValue’s value is changed, all of the parts moved based on the NumberValue’s value. That’s what I would recommend.

If you’re still interested in some help, please reply.