Play animation on keybind

I have an Animation in rep storage, and viewmodel in player camera

How could i play that specific animation in the specific viewmodel with a Keybind

Example like: reloading which uses the current viewmodel and on R it Plays reload anim

If you want to run a animation inside of a viewportModel then please read the following.

First you’ll have to load the animation into the humanoid, you can do this by doing:

local humanoid = viewPort:FindFirstChild("Humanoid")
local animation = humanoid:LoadAnimation(game.ReplicatedStorage.AnimationName)

Now that the animation is loaded into the character, we can use simple tween/audio commands such as:

animation:Play()
animation:Stop()
animation:Pause()
animation:Resume()

if you want the animation to play when you click a keybind, for example R, you can use UserInputService to detected when a key is clicked. For example:

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(userInput)
 if userInput.KeyCode == Enum.KeyCode.R then
  animation:Play()
 end
end)

Hopefully that fixes your problem, please tell me if you have any questions or issues with this.

Im pretty sure you have to use world models for the rig in a viewport if you want it to animate.

Just add a world model in the viewport frame and put the rig in the world model and the you can animate it

Is this still valid if the vm is being cloned into camera

Yes, aslong as your viewport model has a humanoid in it, the animations will still function.

image

They dont have a humanoid