Viewport (World Model) Animations don't work

I know that I probably shouldn’t report it in bug reports, but it feels like bug because it works in workspace and other place

Animations work in workspace (With basically same way of getting and playing animation)
Animations for models in viewport appear in “PlayingAnimationTracks”
It works in other place (with different script but that uses basically same way of getting and playing animation)

I’ve asked help from other people, none helped
Final script with help from other peopl

function module.LoadViewport(Template: Frame, ToiletName)
	local Model = game:GetService("ReplicatedStorage").Assets.Toilets:FindFirstChild(ToiletName)
	if not Model then return end
	
	local ViewportFrame: ViewportFrame = Template:WaitForChild("ViewportFrame")
	local WorldModel: WorldModel = ViewportFrame:WaitForChild("WorldModel")
	
	local NewModel: Model = Model:Clone()
	for i,v in pairs(NewModel:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = false
		end
	end
	--NewModel.HumanoidRootPart.Anchored = true
	--NewModel.Parent = WorldModel
	
	local Position = NewModel:GetPivot() * CFrame.new(-5, -1.5, -5)
	local LookAt = CFrame.lookAt(Position.Position, NewModel.PrimaryPart.Position)
	
	local Camera = Instance.new("Camera")
	Camera.CFrame = LookAt
	Camera.Parent = ViewportFrame
	
	ViewportFrame.CurrentCamera = Camera
	
	
	task.spawn(function()
		Model.Parent = workspace
		Model.Parent = WorldModel
		
		local hum = NewModel:FindFirstChildOfClass("Humanoid")
		local anim = if game:GetService("ReplicatedStorage").Assets.Anims:FindFirstChild(ToiletName) then game:GetService("ReplicatedStorage").Assets.Anims:FindFirstChild(ToiletName).Idle else game:GetService("ReplicatedStorage").Assets.Anims.Toilet.Idle

		local CloneAnim = Instance.new("Animation")
		CloneAnim.AnimationId = "rbxassetid://74789765315759"
		CloneAnim.Parent = NewModel
		print(CloneAnim.Name, CloneAnim.AnimationId)

		local Animator = hum:FindFirstChildOfClass("Animator") or Instance.new("Animator", hum)

		local Animation = Animator:LoadAnimation(CloneAnim)
		Animation.Looped = true

		Animation:Play()
		local animTracks = Animator:GetPlayingAnimationTracks()
		local animationTrack: AnimationTrack = animTracks[1]
		
		animationTrack:Stop()
		task.wait(0.1)
		animationTrack:Play()
		--for i=1, 10 do
		--	Animation:Play()
		--	print("Trying to play animation:", ToiletName)
		--	task.wait(2)
		--end
	end)
end

Script before help from other people

function module.LoadViewport(Template: Frame, ToiletName)
	local Model = game:GetService("ReplicatedStorage").Assets.Toilets:FindFirstChild(ToiletName)
	if not Model then return end

	local ViewportFrame: ViewportFrame = Template:WaitForChild("ViewportFrame")
	local WorldModel: WorldModel = ViewportFrame:WaitForChild("WorldModel")

	local NewModel: Model = Model:Clone()
	for i,v in pairs(NewModel:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = false
		end
	end
	NewModel.Parent = WorldModel

	local hum = NewModel:FindFirstChildOfClass("Humanoid")
	local anim = if game:GetService("ReplicatedStorage").Assets.Anims:FindFirstChild(ToiletName) then game:GetService("ReplicatedStorage").Assets.Anims:FindFirstChild(ToiletName).Idle else game:GetService("ReplicatedStorage").Assets.Anims.Toilet.Idle



	local Animator = hum:FindFirstChildOfClass("Animator") or Instance.new("Animator", hum)
	local Animation = Animator:LoadAnimation(anim)
	Animation.Looped = true
	Animation:Play()

	--print(Animator:GetPlayingAnimationTracks())

	local Position = NewModel:GetPivot() * CFrame.new(-5, -1.5, -5)
	local LookAt = CFrame.lookAt(Position.Position, NewModel.PrimaryPart.Position)

	local Camera = Instance.new("Camera")
	Camera.CFrame = LookAt
	Camera.Parent = ViewportFrame

	ViewportFrame.CurrentCamera = Camera
end

Script in other place

local module = {}

function module.GetAnimationTrack(Model: Model, animName: string)
	local Humanoid = Model:FindFirstChildOfClass("Humanoid")
	
	local AnimationControl
	if Humanoid then
		AnimationControl = Humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", Humanoid)
	else
		AnimationControl = Model:FindFirstChildOfClass("AnimationController") or Instance.new("AnimationController", Model)
	end
	
	local AnimationsFolder = Model:FindFirstChild("Animations")
	local AnimationInstance = (AnimationsFolder and AnimationsFolder:FindFirstChild(animName))
	if not AnimationInstance then
		warn("Couldn't find animation:", animName)
		return
	end
	if not AnimationInstance:IsA("Animation") then
		warn("Found instance class name is not Animation:", AnimationInstance.Name)
		return
	end
	
	local PlayingAnimTracks = AnimationControl:GetPlayingAnimationTracks()
	
	local requiredAnim
	for i,v: AnimationTrack in pairs(PlayingAnimTracks) do
		if v.Name == animName then
			requiredAnim = v
			break
		end
	end
	
	if not requiredAnim then
		requiredAnim = AnimationControl:LoadAnimation(AnimationInstance)
	end
	
	return requiredAnim
end

function module.SetupViewportAnimation(frame: Frame, Model: Model, parent)
	if not frame.Parent or not frame.Parent.Parent or not frame.Parent.Parent.Parent then -- (Just not frame.Parent would be enough though, I think so at least)
		if not parent then
			warn("Couldn't set animation, because frame is not parented and parent is not given")
			return
		end
		
		frame.Parent = parent
	end
	
	local ViewportFrame = frame:FindFirstChildOfClass("ViewportFrame")
	if not ViewportFrame then return end
	local WorldModel = ViewportFrame:FindFirstChildOfClass("WorldModel")
	if not WorldModel then return end
	
	Model = Model or WorldModel:FindFirstChildOfClass("Model")
	
	if not Model then
		warn("Couldn't set animation, because model not found")
		return
	end
	
	local AnimName = Model:GetAttribute("ViewportAnim") or shared.Settings.Viewports.Default_Idle_Animation_Name
	
	local AnimationTrack: AnimationTrack = module.GetAnimationTrack(Model, AnimName)
	if not AnimationTrack then
		warn("Couldn't find animation track:", AnimName)
		return
	end
	
	AnimationTrack:Play()
end

return module

Expected behavior

Animation should play in viewport/WorldModel, but it does not

Viewport animations work fine, this looks like a scripting issue. Regardless you should upload a place file for reproduction.

1 Like

For some reason the server script with same way of getting animation and playing it works fine
(Like they’re similar in part of playing animation)

Also, my friend uploaded animations not in group, but they dont work not because of this but a different reason
They work for him in workspace but not viewport frame
For me it says (The x6 one is animation I’m trying to play)
image
Which I think (not sure) means it plays it correctly

To give the file I’ll have to cut most things so gonna need some time

Salutations!

Thanks for bringing this to our attention.
A ticket was filed, and we’ll start investigating.

Is this issue still happening at your end?
If so, we would need the Repro Placefile to move forward with the investigation.
We’ll stay tuned for it.

If you need assistance or info on which info/files would be relevant to investigate this topic or how to get them, please refer to the How to post a Bug Report - Bug Reports - Developer Forum | Roblox

Thanks for understanding!
Have A Nice Day!

Where exactly do I send the file to?

Greetings!

Thanks for following up on this thread.
Usually, this is where every file or log is sent; that’s how engineers can check them and investigate the issue:

From the How to post a Bug Report - Bug Reports - Developer Forum | Roblox post I attached.

Thanks for understanding.
Have a Nice Day!

We tried to reproduce the bug but couldn’t. Please provide more details or steps for us to continue investigating this issue.