#Fire Animation not playing

5 messages · Page 1 of 1 (latest)

wintry summit
severe pasture
#

the issue might be the way animations are played. specifically the AnimationController should be used to control animations on a humanoid rather than directly on the ViewModel instance.

#

ill remake your code for you.

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

local UIS = game:GetService("UserInputService")
local RunServ = game:GetService("RunService")

local swayAmmount = .2;
local swayCF = CFrame.new()
local lastCameraCf = CFrame.new()

local fireAnim = nil

local framework = {
    inventory = {
        "Glock17";
    };

    module = nil;
    viewmodel = nil;
}

function loadSlot(Item)
    local ViewModelFolder = game:GetService("ReplicatedStorage").Viewmodels
    local ModulesFolder = game:GetService("ReplicatedStorage").Modules

    if ModulesFolder:FindFirstChild(Item) then
        framework.module = require(ModulesFolder:FindFirstChild(Item))

        if ViewModelFolder:FindFirstChild(Item) then
            framework.viewmodel = ViewModelFolder:FindFirstChild(Item):Clone()
            framework.viewmodel.Parent = Camera

            fireAnim = Instance.new("Animation")
            fireAnim.Parent = framework.viewmodel
            fireAnim.Name = "Fire"
            fireAnim.AnimationId = framework.module.fireAnim
            fireAnim = framework.viewmodel.AnimationController:LoadAnimation(fireAnim)
        end
    end
end

RunServ.RenderStepped:Connect(function()
    local rot = Camera.CFrame:ToObjectSpace(lastCameraCf)
    local X, Y, Z = rot:ToOrientation()
    swayCF = swayCF:Lerp(CFrame.Angles(math.sin(X) * swayAmmount, math.sin(Y) * swayAmmount, 0), .1)
    lastCameraCf = Camera.CFrame

    local Humanoid = Character:WaitForChild("Humanoid")

    if Humanoid then
        for _, v in pairs(Camera:GetChildren()) do
            if v:IsA("Model") then
                v:SetPrimaryPartCFrame(Camera.CFrame * swayCF)
            end
        end
    end
end)

loadSlot(framework.inventory[1])

UIS.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        fireAnim:Play()
    end
end)