How to tween character parts?

Is there a better way of doing this like a more modern way (without using animations)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()

local remoteEvents = ReplicatedStorage.RemoteEvents

local WeldManager = {}

local appendigeNames = {
	"Right Arm",
	"Left Arm",
	"Right Leg",
	"Left Leg",
	"Head"
}
local correspondingJointNames = {
	"Right Shoulder",
	"Left Shoulder",
	"Right Hip",
	"Left Hip",
	"Neck"
}

function WeldManager:tweenWeld(targetCharacter: Model, part1: BasePart, startCFrame: CFrame, endCFrame: CFrame, tweenInfo: TweenInfo)
	if targetCharacter == character then
		remoteEvents.ReplicateTweenWeld:FireServer(targetCharacter, part1, startCFrame, endCFrame, tweenInfo.Time, tweenInfo.EasingStyle, tweenInfo.EasingDirection)
	end

	local torso = targetCharacter:FindFirstChild("Torso")

	if not torso then
		return
	end

	local weldExists = false
	local weld

	for index, descendant in ipairs(targetCharacter:GetDescendants()) do
		if descendant:IsA("Weld") then
			if descendant.Part1 == part1 then
				weldExists = true
				weld = descendant
			end
		end
	end
	if not weldExists then
		weld = Instance.new("Weld")
	end

	for index, appendigeName in pairs(appendigeNames) do
		local appendige = targetCharacter[appendigeName]

		if appendige then
			if part1 == appendige then
				local jointName = correspondingJointNames[index]
				local joint = torso[jointName]

				if joint then
					joint.Part1 = nil

					weld.Part0 = torso
					weld.Part1 = part1
					weld.C0 = startCFrame
					weld.Parent = torso
					TweenService:Create(weld, tweenInfo, {C0 = endCFrame}):Play()
				end
			end
		end
	end
end

function WeldManager:resetWelds(targetCharacter: Model)
	if targetCharacter == character then
		remoteEvents.ReplicateResetWelds:FireServer(targetCharacter)
	end

	local torso = targetCharacter:FindFirstChild("Torso")

	if not torso then
		return
	end

	for index, descendant in ipairs(torso:GetDescendants()) do
		if descendant:IsA("Weld") then
			descendant:Destroy()
		end
	end

	for index, jointName in pairs(correspondingJointNames) do
		jointName = correspondingJointNames[index]
		local joint = torso[jointName]

		if joint then
			local appendigeName = appendigeNames[index]
			local appendige = targetCharacter[appendigeName]

			if appendige then
				joint.Part1 = appendige
			end
		end
	end
end

return WeldManager

I don’t see why you would need to tween character parts? It takes so much more effort than animations.

There probably isn’t a modern way except animations.

1 Like

Okay, I just feel like the problem with animations is that I have like specific time values in my scripts that the animations need to end by, I think I will try using animations.

You can adjust the speed at which your animation runs, or just focus on making your animation actually last the idealized duration

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