Viewmodel animation not working

hello, so, I tried to make a viewmodel with an animation, I used moon animator to make the animation, and after finishing the animation I published it on roblox, so I made a local script based on a script from a post I saw on Devforum, so I tried to put the animation but for some reason it doesn’t work

here is the viewmodel:
image

a picture of the problem:

here’s the code (i made an Localscript, and put it on StarterPlayerScripts)

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")

-- Carregue a animação do ReplicatedStorage
local rp = game:GetService("ReplicatedStorage")
local viewmodel = rp.Main.bracos.Viewmodel2
viewmodel.Parent = workspace.Camera
-- Crie uma nova instância "Animação" e atribua um ID de ativo de animação
local idleAnimation = Instance.new("Animation")
idleAnimation.AnimationId = "rbxassetid://14705098812"

-- Carregue a animação no animador
local idleAnimationTrack = animator:LoadAnimation(idleAnimation)


-- Defina a prioridade da animação para inativo
idleAnimationTrack.Priority = Enum.AnimationPriority.Movement

-- Reproduza a faixa de animação em loop
idleAnimationTrack:Play()
idleAnimationTrack.Looped = true

local uis = game:GetService("UserInputService")
local runservice = game:GetService("RunService")

local camera = workspace.CurrentCamera

local bobCF = CFrame.new()
local swayCF = CFrame.new()

local running = 0

runservice.RenderStepped:Connect(function()
	local mouseDelta = uis:GetMouseDelta()/50 -- divida pelo valor que desejar

	if hum.MoveDirection.Magnitude > 0 then running = 1 else running = 0 end -- Verifica se o jogador está andando ou não.

	local swayX =  math.clamp(mouseDelta.X, -0.2,0.2) -- Nós limitamos para que não tenhamos resultados estranhos
	local swayY = math.clamp(mouseDelta.Y, -0.2,0.2)

	local bobX = math.cos(tick() * 5 * hum.WalkSpeed/16) * .2 -- Os números dentro dos () fazem a velocidade, e o .2 é a intensidade, tanto para o Y quanto para o X
	local bobY = math.abs(math.sin(tick() * 6 * hum.WalkSpeed/16) * .3)

	bobCF = bobCF:Lerp(CFrame.new(bobX * running,bobY * running,0) , .4) -- Torna suave
	swayCF = swayCF:Lerp(CFrame.new(swayX, swayY, 0), .3)

	viewmodel.Camera.CFrame = camera.CFrame * bobCF * swayCF -- Pronto

end)

please someone help me

1 Like

Try using AnimationController

1 Like

YOO, thank you man it’s worked

1 Like

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