Trying to play an animation of a character in my plugin, but the cframe values won’t change correctly. Here is the original animation made in the animation editor:
And heres what happened when I tried running it with a plugin, poses exported from the saved animation (changing c0 values)
The script
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local StudioService = game:GetService("StudioService")
local camera = workspace.CurrentCamera
local character
local animTweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
--local userId = StudioService:GetUserId()
local userId = 1
local updateConnection
local function createCharacter(id)
local dummy = script.Parent.Dummy:Clone()
character = dummy
dummy.Name = tostring(id)
dummy.Parent = workspace.Terrain
character.PrimaryPart.CFrame += Vector3.new(10, 0, 0)
for _, part in pairs(dummy:GetDescendants()) do
if part:IsA("BasePart") then
part.Locked = true
end
end
for _, motor6D in pairs(dummy:GetDescendants()) do
if motor6D:IsA("Motor6D") then
local originalC0 = Instance.new("CFrameValue")
originalC0.Name = "OriginalC0"
originalC0.Parent = motor6D
originalC0.Value = motor6D.C0
end
end
coroutine.resume(coroutine.create(function()
while dummy do
wait()
print(dummy)
for _, motor6D in pairs(dummy:GetDescendants()) do
if motor6D:IsA("Motor6D") then
for _, pose in pairs(script.Parent.Pose1:GetDescendants()) do
if motor6D.Part1.Name == pose.Name then
local motorPos = motor6D.OriginalC0.Value.Position
local posePos = pose.CFrame.Position
local motorRotX, motorRotY, motorRotZ = motor6D.OriginalC0.Value:ToEulerAnglesXYZ()
local poseRotX, poseRotY, poseRotZ = pose.CFrame:ToEulerAnglesXYZ()
TweenService:Create(motor6D, animTweenInfo, {
C0 = CFrame.new(
motorPos.X + posePos.X,
motorPos.Y + posePos.Y,
motorPos.Z + posePos.Z
) * CFrame.Angles(
motorRotX + poseRotX,
motorRotY + poseRotY,
motorRotZ + poseRotZ
)
}):Play()
end
end
end
end
wait(2)
for _, motor6D in pairs(dummy:GetDescendants()) do
if motor6D:IsA("Motor6D") then
for _, pose in pairs(script.Parent.Pose2:GetDescendants()) do
if motor6D.Part1.Name == pose.Name then
local motorPos = motor6D.OriginalC0.Value.Position
local posePos = pose.CFrame.Position
local motorRotX, motorRotY, motorRotZ = motor6D.OriginalC0.Value:ToEulerAnglesXYZ()
local poseRotX, poseRotY, poseRotZ = pose.CFrame:ToEulerAnglesXYZ()
TweenService:Create(motor6D, animTweenInfo, {
C0 = CFrame.new(
motorPos.X + posePos.X,
motorPos.Y + posePos.Y,
motorPos.Z + posePos.Z
) * CFrame.Angles(
motorRotX + poseRotX,
motorRotY + poseRotY,
motorRotZ + poseRotZ
)
}):Play()
end
end
end
end
wait(2)
end
end))
dummy.Humanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(id))
end
RunService:BindToRenderStep("UpdateCharacter", Enum.RenderPriority.Last.Value, function()
if character == nil then
createCharacter(userId)
end
end)
plugin.Unloading:Connect(function()
RunService:UnbindFromRenderStep("UpdateCharacter")
if character ~= nil then
character:Destroy()
end
end)