How do you tween the position of a weld?

Hello DevForum,

Recently I have been trying to tween the size and position of a part that is welded by script to the player. But I cannot seem to figure out why it does not tween the position of the welded part when I try to in the script.

I am pretty new to welds, and all the research on this topic has not given me an answer to my question. Maybe I am just doing it wrong and I am sorry if this has been posted before.

Here is the server script that clones the part and welds the part to the player, then tweens it.

Server Script:

-- Variables --

local TS = game:GetService("TweenService")

local SS = game:GetService("ServerStorage")
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Activate")

local EffectPartsFolder = SS:WaitForChild("EffectParts")
local LeftArmPart = EffectPartsFolder.LeftArmEffectPart:Clone()


-- Main Function // Event Fire --

Event.OnServerEvent:Connect(function(Player)
	
	local function WeldAndTween()
		
		LeftArmPart.Parent = Player.Character["Left Arm"]
		LeftArmPart.CFrame = Player.Character["Left Arm"].CFrame * CFrame.new(0, -0.2, 0) * CFrame.Angles(0, 0, 0)
		
		local LeftArmWeld = Instance.new("Weld")
		LeftArmWeld.Part0 = Player.Character["Left Arm"]
		LeftArmWeld.Part1 = LeftArmPart
		LeftArmWeld.C0 = Player.Character["Left Arm"].CFrame:Inverse()
		LeftArmWeld.C1 = LeftArmPart.CFrame:Inverse()
		LeftArmWeld.Parent = LeftArmPart
		
		local LeftArmGoals = {
			Size = Vector3.new(1.1, 2.05, 1.1);
			Position = LeftArmPart.Position * Vector3.new(0, 0.2, 0)
		}
		
		local LeftArmTween = TS:Create(
			LeftArmPart,
			TweenInfo.new(0.8, Enum.EasingStyle.Quart),
			LeftArmGoals
		):Play()
		
	end
	
	WeldAndTween()
	
end)

I believe I’ve done everything right, because everything works besides the position changing which you can see I placed it here.

local LeftArmGoals = {
			Size = Vector3.new(1.1, 2.05, 1.1);
			Position = LeftArmPart.Position * Vector3.new(0, 0.2, 0)
		}

Once again I am sorry if this has been posted before or answered already but I cannot find anything on the DevForum or the internet that helps my situation.

2 Likes

For welds, you need to use CFrame and not Position/Orientation.

So

local LeftArmGoals = {
			Size = Vector3.new(1.1, 2.05, 1.1);
			CFrame= LeftArmPart.CFrame* Vector3.new(0, 0.2, 0)
		}
1 Like

image

This is the error it gives me, I assumed it was because it was a CFrame so I switched the

Vector3.new(0, 0.2, 0)

To

CFrame.new(0, 0.2, 0)

But it still gives me the same problem, it won’t tween or change the position at all.

you see TweenService is only used for 1 Property so be careful when tweening an Objects Properties and your Usage of it is not correct try to recode it and see if it works!

1 Like

Even if I placed them into separate tweens, it still does not change the position of the welded part, you see I am trying to make an effect from where it goes from the hand to the shoulder, but the position will not change.

Welded Parts don’t move actually since its connected to another one, mind using a motor6d for this one?

1 Like

I would tween the C0 property of the weld using TweenService. If you have a sequence of CFrames for the C0, I recommend making a new Tween via TweenService:Create() So that they override the previous one.

1 Like

So it actually started moving it, which is great, any tips on how to calculate where it goes. As of now it’s weird and goes in different directions when I use this.

local LeftArmTween2 = TS:Create(
			LeftArmWeld,
			TweenInfo.new(0.8, Enum.EasingStyle.Quart),
			{C0 = Player.Character["Left Arm"].CFrame + Vector3.new(0, 0, 0)}
		):Play()

You could insert a dummy in the workspace, and move around the bodypart you want to be animated via the rotation and move tool in studio and print the offset of the said part into the output, record the output as a CFrame and use that.

For example in the picture below I rotated the arm with the move and rotate tool in studio.


I then record the offset of the arm by printing it

print(game.Workspace.Dummy["Left Arm"].CFrame:ToObjectSpace(game.Workspace.Dummy.Torso.CFrame))

This gets printed

And I use that CFrame as the C0’s tween goal in the tweenservice part.

local LeftArmTween = TweenService:Create(LeftArmWeld,TweenInfo.new(.8,
    Enum.EasingStyle.Quart,
    {C0 = CFrame.new( 1.00404358, 0.479166031, 0.759120941, 0.835734427, 0.174246058, -0.520755649, 0.26809898, 0.698148847, 0.663860738, 0.47924009, -0.694425344, 0.536751807)}))
LeftArmTween:Play()

I hope this makes sense.

C0 is basically the CFrame offset for Part1 from Part0 and C1 is the offset of C0(offset of the offset), but you don’t really need to use C1 at all for what you’re doing.

2 Likes

I think it makes a bit of sense to me, but I don’t understand it completely even after looking it up. But it seems to not do anything for me, as it still does the same thing shown below.

https://gyazo.com/b2ec10ffc9da07713bd957131fc29d38

I am probably using it wrong, but I am not sure.

local info = TweenInfo.new(1, Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local goals = {CFrame = Part.CFrame * CFrame.new(0,0,-5)
local Tween = game:GetService("TweenService"):Create(--YourPart,info,goals)
Tween:Play()

This is how I tween so. Wrote this on my phone might have some errors.

1 Like

You could also do something like this:

local cfValue = Instance.new('CFrameValue')
cfValue.Value = weld.C0

local base = weld.C0--the value all movement will be relative to

cfValue.Changed:Connect(function()
    weld.C0 = cfValue.Value
end)

local goal = {Value = base * pos} --pos is the desired position relative to the base value

local cfTween = ts:Create(cfValue,info,goal)
cfTween:Play()

This just tweens a CFrameValue which is connected to the weld using Changed. When the CFrameValue changes, the weld’s CFrame changes.

4 Likes

This really helped me! Thanks a bunch, this has been one of my biggest problems with welds.

1 Like

What do you put inside the position like Vector3.new or CFrame. Also the script looks amazing

1 Like