Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my animation playing for my custom viewmodel?

Asked by 5 years ago

Hi everyone!

I am having trouble with playing animations for my custom viewmodel I have made. The animations work fine if I put the viewmodel in Workspace, but they just wont play if they're in the camera. I also get no error messages in the console.

Here's the code for the view model:

--//Variables\\--
local cam = workspace.CurrentCamera
local reps = game:GetService("ReplicatedStorage")
local runs = game:GetService("RunService")
local Magnum = reps:WaitForChild("Gun"):Clone()

--//Connecting To The Camera\\--
for i,v in pairs (Magnum:GetChildren()) do
    if v:IsA("BasePart") then
        if v ~= Magnum.PrimaryPart then
            local weld = Instance.new("Weld")
            weld.Part0 = Magnum.PrimaryPart
            weld.Part1 = v
            weld.C0 = Magnum.PrimaryPart.CFrame:inverse()
            weld.C1 = v.CFrame:inverse()
            weld.Name = v.Name
            weld.Parent = Magnum.PrimaryPart
        end
    end
end

Magnum.Parent = cam

--Viewmodel Position--
runs.RenderStepped:connect(function()
    Magnum:SetPrimaryPartCFrame(cam.CFrame*CFrame.new(0,-2,-2))
end)


I also made a separate script that goes into the viewmodel. Here's the code:

local Magnum = script.Parent
local Hum = Magnum:WaitForChild("Humanoid")
local Animations = Magnum:WaitForChild("Animations")

--//Animations\\--
local Hold = Hum:LoadAnimation(Animations.Hold)
local Idle = Hum:LoadAnimation(Animations.Idle)

--Looped Animations--
Hold.Looped = true
Idle.Looped = true

Idle:Play()

Help is appreciated! Thanks!

1 answer

Log in to vote
0
Answered by 5 years ago

Are you certain you rigged it correctly?

0
Yes, If I put the viewmodel into Workspace and I test the game, it will do the animation just fine. It just wont work when it's in the camera. spartanlord456 19 — 5y
Ad

Answer this question