Cloned Char of a Player in a ViewportFrame won't play an Animation

Getting back into Roblox Studio after a year of inactivity, may be a simple solution idk.

  1. What do you want to achieve? I am trying to make a ViewportFrame of the LocalPlayer’s cloned char, and then make it play the R15 Default Idle2 Roblox Animation.

Explorer and ViewportFrame Properties

  1. What is the issue? The Cloned Character appears on screen and in the correct position, but the animation doesnt seem to play. I tried using ChatGPT for help, but it couldn’t seem to help. It suggested using WorldModels, removing the Animate script from the cloned char and using an Animator object, which I tried but didn’t seem to also work.

  2. What solutions have you tried so far? Tried to find one, couldn’t seem to find a solution for this exact thing (maybe there is, idk)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here’s how the UI and Outputs looks when I start the game:

Local Script inside of the ViewportFrame:

local viewportFrame = script.Parent
local characterCam = Instance.new("Camera")
characterCam.Name = "CharacterCam"
characterCam.Parent = viewportFrame

viewportFrame.CurrentCamera = characterCam

local idleAnim = Instance.new("Animation")
idleAnim.AnimationId = "rbxassetid://507766666" -- R15 idle

print("ran")

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

repeat wait() until player:HasAppearanceLoaded()

local char = player.Character or player.CharacterAdded:Wait()
char.Archivable = true

local worldModel = Instance.new("WorldModel")
worldModel.Parent = viewportFrame

local clonedChar = char:Clone()

if clonedChar:FindFirstChild("Animate") then
	clonedChar.Animate:Destroy()
end

for _, part in clonedChar:GetDescendants() do
	if part:IsA("BasePart") then
		part.Anchored = true
		part.CanCollide = false
	end
end

clonedChar.Parent = worldModel

local humanoid = clonedChar:FindFirstChildOfClass("Humanoid")

print("RigType:", humanoid.RigType)

local anim = humanoid:LoadAnimation(idleAnim)
anim.Looped = true
anim:Play()

print("isAnim playing: " .. tostring(anim.IsPlaying))
-- Anchor and set camera
local hrp = clonedChar:FindFirstChild("HumanoidRootPart")
if hrp then
	hrp.Anchored = true

	local camDistance = -6
	local camPos = hrp.Position + Vector3.new(0, 1, camDistance)
	
	characterCam.CFrame = CFrame.new(camPos, hrp.Position)
end
1 Like

If I recall correctly, animations cannot be played inside of viewport frames.
From further searching this seems to be an issue, but there appears to be a work around!

If you insert a WorldModel into the ViewportFrame, and then put the character inside of the WorldModel, you should be able to animate it.

My sources:

2 Likes

It’s not a workaround it’s literally a feature

That’s because you need to load the animation in the “Animator” instanced parented to the humanoid and not the humanoid itself.

@FroDev1002, please view the script posted by OP. They are using a world model.

@FroDev1002 and @5haggyyy, I’ve already tried using WorldModels and using the Animator object instead of the Humanoid to load the Animation, and it still doesn’t work. Here is my updated script with me using the Animator instead (I already was using the WorldModel before):

local viewportFrame = script.Parent
local characterCam = Instance.new("Camera")
characterCam.Name = "CharacterCam"
characterCam.Parent = viewportFrame

viewportFrame.CurrentCamera = characterCam

local idleAnim = Instance.new("Animation")
idleAnim.AnimationId = "rbxassetid://507766666" -- R15 idle

print("ran")

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

repeat wait() until player:HasAppearanceLoaded()

local char = player.Character or player.CharacterAdded:Wait()
char.Archivable = true

--I create the worldModel
local worldModel = Instance.new("WorldModel")
worldModel.Parent = viewportFrame

local clonedChar = char:Clone()

if clonedChar:FindFirstChild("Animate") then
	clonedChar.Animate:Destroy()
end

for _, part in clonedChar:GetDescendants() do
	if part:IsA("BasePart") then
		part.Anchored = true
		part.CanCollide = false
	end
end

--Parent the clonedChar to the worldModel
clonedChar.Parent = worldModel

local humanoid = clonedChar:FindFirstChildOfClass("Humanoid")

print("RigType:", humanoid.RigType)

--create an Animator if its not already there
local animator = humanoid:FindFirstChildOfClass("Animator")
if not animator then
	animator = Instance.new("Animator")
	animator.Parent = humanoid
end

--load the anim
local anim = animator:LoadAnimation(idleAnim)
anim.Looped = true
anim:Play()

print("isAnim playing: " .. tostring(anim.IsPlaying))
local hrp = clonedChar:FindFirstChild("HumanoidRootPart")
if hrp then
	hrp.Anchored = true

	local camDistance = -6
	local camPos = hrp.Position + Vector3.new(0, 1, camDistance)
	
	characterCam.CFrame = CFrame.new(camPos, hrp.Position)
end

Okay nevermind, I found the issue, when I was using ChatGPT Previously to help troubleshoot the problem, it suggested to anchor and set CanCollide = false of every BasePart in the char, which seemed to mess up the ability of it to play the animation. I removed this chunk of code and it works just fine:

for _, part in clonedChar:GetDescendants() do
	if part:IsA("BasePart") then
		part.Anchored = true
		part.CanCollide = false
	end
end

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