Animations will not play when a player's cloned character is displayed within Viewport Frame

For the past couple of days, I’ve been messing around with Viewport Frames and cloning the player’s character to display within the Viewport Frame via script for GUI purposes, and its been a very interesting experience so far. However, 10% of that experience was progress and 90% of it was a complete roadblock on doing something as simple as making an animation play on the player’s cloned character displayed in a Viewport Frame. I’ve been trying to find a solution to this issue, both by myself and hours of searching through forums, but I genuinely cannot find one that helps since it’s so specific. These are the hierarchies, script, and video of what happens (and also what the animation is supposed to look like. FYI, there are no errors within the output.)

image

https://cdn.discordapp.com/attachments/878734193809563702/1268724591249854565/2024-08-01_19-16-12.mp4?ex=66ad775a&is=66ac25da&hm=9b1faa6a033da2ef032159a8b2e0d03bcb6a84feca85365efc16a90ab3bf4db4&

(video ^^^)

-- Variables
local uis = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local MouseInDisplay, HoldInDisplay = false, false

local currentX

-- Character Display
local VPFcam = Instance.new("Camera"); VPFcam.Parent = script.Parent.ViewportFrame
VPFcam.CFrame = CFrame.new(0,0,0)
script.Parent.ViewportFrame.CurrentCamera = VPFcam

repeat wait(.1) until game:IsLoaded()

char.Archivable = true

local ClonedChar = char:Clone()

ClonedChar.Parent = script.Parent.ViewportFrame.WorldModel
ClonedChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,-9.5),Vector3.new(0,0,0)))

-- Turning Feature
uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		if MouseInDisplay == true then
			HoldInDisplay = true
			currentX = nil
		end
	end
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		HoldInDisplay = false
	end
end)

script.Parent.ViewportFrame.MouseMoved:Connect(function(X,Y)

	if HoldInDisplay == false then return end
	
	if currentX then ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,((X-currentX)*.025),0) end
	
	currentX = X
end)

script.Parent.ViewportFrame.MouseEnter:Connect(function() MouseInDisplay = true end)
script.Parent.ViewportFrame.MouseLeave:Connect(function() MouseInDisplay = false end)

-- Animations 

local animation = ClonedChar.Humanoid:LoadAnimation(script.Test)
animation:Play()

(I’ve also have not made the entirety of this script just to note)

I’m assuming there might be a very low chance that this is a bug because the :LoadAnimation() only works when a humanoid is in a workspace (because when the “ClonedChar.Parent =” is parented to the workspace, the animation applied on the clone via script will play within the workspace, but not within the WorldModel in the Viewport Frame), but when I use the same script but with a R6 rig within the WorldModel, for some reason, it works, but doesn’t work when the player is cloned? I’m not entirely sure, but if anyone has a fix for this, or would like to attempt to fix this, that would be greatly appreciated.

2 Likes

Although I’m not too certain what causes your issue, an alternative i can suggest is this:

  1. insert a premade rig (like you did before)
  2. get the players hunanoid description using playerservice:GetHumanoidDescription
  3. apply that humanoid appearance to the humanoid

this way you can have a copy of your character in the viewport frame and you can animate it all you want

1 Like

I saw your reply without really knowing what the :GetHumanoidDescription() thing really was, and thought it would work hypothetically, but to no success. I’m assuming when you say “apply that humanoid appearance to the humanoid”, I think you’re referring to the :ApplyDescription() thing, which would work, but I don’t think there’s an actual :GetHumanoidDescription() that gets the humanoid description of something locally. There isn’t an actual :GetHumanoidDescription:(), it always has to end with something else like, :GetHumanoidDescriptionFromUserID(), which isn’t what I’m looking for, unfortunately, but I do appreciate your help, though I could be scripting it incorrectly.

2 Likes

Figured it out. Apparently, the line at the bottom of the script that says,

local animation = ClonedChar.Humanoid:LoadAnimation(script.Test)

was supposed to be,

local animation = ClonedChar:WaitForChild("Humanoid"):LoadAnimation(script.Test)
2 Likes

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