Why does my Motor6D tweening function not work?


#1

I’m trying to make a Studio plugin that allows you to take an animation and convert it into something useable on any game through the use of a module.

This was made for use in Script Builders, but could be convenient for anyone trying to create animations for multiple games with multiple ownerships.

For example, let’s say you made a nice sword and want to share it with a few of your friends.
It would be annoying to have your friends re-upload a bunch of animations.

The idea is that the plugin creates a module with a Roblox animation’s KeyframeSequence inserted inside of it.
The module would simply return the KeyframeSequence.
Then, the plugin prompts you to upload this as a MainModule and you can use the MainModule’s ID as the custom animation ID.
From there, you would use another pre-written module that I provide to load the animation using the created custom animation ID.

TLDR:
Making “Roblox animation to anyone-can-use-anywhere animation” converter through the use of Modules.
This function not working is prohibiting me from doing so.

Code not working as intended:

function tweenPose(motor,cframe,speed)
	speed = speed or 1 
	local tweenInfo = TweenInfo.new(speed)
	print(motor,cframe.p,speed)
	TweenService:Create(motor, tweenInfo, {["Transform"]=cframe}):Play()
end

The print confirms that the function gets all the information, but it never makes my character change in any way.

This is on a server sided script, so it can’t be anything related to server/client sides.
(no errors either)

Links:
https://developer.roblox.com/api-reference/property/Motor6D/Transform
https://developer.roblox.com/api-reference/function/TweenService/Create

Full code:


#2

I believe tween info doesn’t support CFrame so you will need to convert to a vector on your TweenService:Create() line.


#3

TweenService does support CFrame but there are a few issues with trying to tween the Transform property.

  • The Transform property doesn’t replicate. If you update this on the server changes will not be replicated to the client.
  • The Transform property should be updated using the Stepped signal of RunService, if updated using RenderStepped or other signals then your updates can be overridden by the currently running animations.
  • TweenService will update it’s tween using the Heartbeat signal on the server and the RenderStepped signal on the client so it is not suitable for updating the Transform property.

Here is some example code which updates the transform property of the local character.

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

if not LocalPlayer.Character then
	LocalPlayer.CharacterAdded:wait()
end

local character = LocalPlayer.Character
if not character.Parent then
	character.AncestryChanged:wait()
end

local humanoid = character:WaitForChild("Humanoid")

-- Example of rotating the RightUpperArm of an R15 character by 90 degrees
local function updateCharacterTransforms()
	local rightArm= character:FindFirstChild("RightUpperArm")
	if not rightArm then
		return
	end

	local shoulderJoint = rightArm:FindFirstChild("RightShoulder")
	if not shoulderJoint then
		return
	end

	local newTransform = shoulderJoint.Transform * CFrame.Angles(math.rad(90), 0, 0)
	shoulderJoint .Transform = newTransform
end

local runServiceConn;
-- Note use of Stepped signal
runServiceConn = RunService.Stepped:connect(function()
	updateCharacterTransforms()
end)

local humanoidDiedConn;
humanoidDiedConn = humanoid.Died:connect(function()
	runServiceConn:disconnect()
	humanoidDiedConn:disconnect()
	runServiceConn = nil
	humanoidDiedConn = nil
end)

For code that replicates tweening to all clients you might want to look at the following:


#4

Thanks for the in-depth response,
but that code isn’t doing anything either
image

(neither on the client side nor the server side)


#5

Whoops, it was looking for the LeftShoulder joint in the right arm. I’ve updated the code and it should work client side now.