Animation doesn't play for Viewmodel when in the local player's camera

I want to make this viewmodel play a certain animation when a key is pressed - But I can’t get the animation to play in the local player when as a viewmodel, even as a loop.

The animation is a simple movement of the arm, where the player moves it closer to the camera to check the watch. This is how it looks when in the workspace, and I was able to play it there.

As a viewmodel, I’m unable to get the animation to play, even though I think it should do it.

The script I used to play it on the SERVER side, on the workspace.

local anim = script:WaitForChild("Animation")
local hum = script.Parent.Humanoid
local AniM = hum:LoadAnimation(anim)
wait(5)
AniM:Play()
AniM.Looped = true

The script I used to attempt to play the animation on the viewmodel while its local

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.Camera
local UIS = game:GetService("UserInputService")

local VM = script.Parent
local hum = VM.Humanoid
local anim1 = Camera.ViewModel.AnimationPlayer["Checking Clock"]
local animA = hum:LoadAnimation(anim1)

while wait(6) do -- This should repeat the animation every 6 seconds I think
	animA:Play()
end

--[[
UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.V then
		animPlay:Play()
		print("Tried to play!")
	end
end)--]]

Explorer image of the viewmodel’s parts. (There is a LOT more but I am rather sure they are irrelevant to this.)
image

All parts except for the HumanoidRootPart are unanchored, and set to not collide. There’s a WorldModel inside of it, but I couldn’t exactly find what to do with it, so it ended up just being there, with the PrimaryPart set to the HumanoidRoot. The viewmodel functions by being copied into the localplayer’s camera, and working from there.

I tried looking for solutions, but couldn’t get anything absolutely that said “Do this! It will help!” Does anyone know what is happening? What am I doing wrong? Anything that would make this simpler?

The entire character should be inside of the world model in order for physics to apply.

2 Likes

No errors, but it still failed to play my animation.


image

First you can try unanchoring the HumanoidRootPart to see if that helps.
Also you can try loading the animation on the animator instead of the humanoid.

1 Like

Tried both, nothing happened. The root part is now unanchored.

I also tried to remake the function playing the animation to a function, but it still didn’t work. What I don’t like is that I am actually not even getting prints when it runs… Or any error at all.

local Camera = workspace.Camera

local VM = script.Parent
local hum = VM.Humanoid
local anim1 = Camera.ViewModel.Humanoid.Animator.Punch
local animA = hum:LoadAnimation(anim1)

local function Animate()
	wait(1)
	anim1.Looped = true
	animA:Play()
end
wait(1)
Animate()

warn("Reached end of script")

I also tried to load on the animator, like this.

local animA = hum.Animator:LoadAnimation(anim1)
1 Like

Okay, i found out myself. Scripts seem to refuse to run when put under my ViewModel (under Camera), and I have to drag all animating from StarterCharacterScripts. I first found out when I put my AnimationPlayer script inside character scripts, changed some values, and it actually started sending the warn() messages.

My scripts would have all worked, but it was simply the issue of them not running at all, for some reason.

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