I want an animation to play on a cloned character in a viewportframe but my issue is that no matter how hard I try I cant seem to get it to work.
Ive read several other devforum threads about this topic but none of them seem to fix my issue.
I currently have my GUI located in StarterGui like this
StarterGui
ScreenGui
ViewportFrame
WorldModel
CharacterModel
LocalScript
Whenever I try to play an animation I print all playing animations with GetPlayingAnimationTracks() and it prints my animation name but no animation is visually being played. When I copy the rig over to workspace and run the same code it plays perfectly there.
Also it may depend on how you get the humanoid, can you send the part where you’re defining the humanoid variable and also all other variables that needed to define humanoid?
How I define humanoid depends on where it is
When the CharacterModel is located in workspace I simply do
local Humanoid = game.Workspace.CharacterModel:FindFirstChild(“Humanoid”)
when the CharacterModel is located in worldmodel I do
local ScreenGui = script.Parent
local ViewportFrame = ScreenGui.ViewportFrame
local WorldModel = ViewportFrame.WorldModel
local Rig = WorldModel.CharacterModel
local Humanoid = Rig:FindFirstChild(“Humanoid”)
When playing the animations outside viewportframe I play them in the same way and it works, it just does not work within the worldmodel for whatever reason.
If I’m not mistaken, models must be a descendant of workspace in order for animations to load.
Parent your viewmodel to workspace, load required animations, store them in an array and then play them when required.
For example:
local loadedAnimations = {}
viewportModel.Parent = workspace
for _, animation in pathToAnimations:GetChildren() do
loadedAnimations[animation.Name] = Animator:LoadAnimation(animation)
end
viewportModel.Parent = viewport
loadedAnimations.Idle:Play()
This is sort of a step forward but it still does not work.
local ScreenGui = script.Parent
local ViewportFrame = ScreenGui.ViewportFrame
local WorldModel = ViewportFrame.WorldModel
local Rig = WorldModel.Rig
local Humanoid = Rig:FindFirstChild(“Humanoid”)
Rig.Parent = game.Workspace
local LoadedAnimations = {}
for _,Animation in script:GetChildren() do
LoadedAnimations[Animation.Name] = Humanoid.Animator:LoadAnimation(Animation)
end
print(LoadedAnimations)
wait(1)
Rig.Parent = WorldModel
LoadedAnimations.Test:Play()
This does not work, Sorry if I missed something you said.
Although I noticed that if an animation is halfway through playing and you move it to worldmodel it completely freezes.
Can you not play animations in worldmodels at all? I thought that was kind of the point of them?
I don’t exactly remember, maybe the animations have to be played in workspace instead of just loaded?
I don’t know, I’ve never used WorldModels and I barely touch Viewport frames because they’re just horrible.
I’d personally just having a scaled down model track the camera’s CFrame, while also being parented to the camera. You’d get better lighting, resolution, materials and everything would just work.
Maybe your animation is having an problem or you didn’t put the animation ID properly.
I did the same thing and it worked perfectly.
Check the animation id and your animation.
Edit: Oh, sorry, if it’s an cloned character, you should review the side of the script where you cloned it. Since GUIS are on local scripts, you should clone it on an local script. Even if its global, you should use an remove event. (Client)
There is nothing wrong with the animation itself.
I can play the exact same animation on my own character at the same time and it’ll play but it will never play in the viewportframe.
Can you share a rblx place file where you got it working?