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

[EDITED] AnimationController object isn't a descendant of the game object?

Asked by 4 years ago
Edited 4 years ago

When the player dies, the script says that the AnimController is not a child of the ViewModel. I dont know why, but here is my error, local script, and module script.

NOTE: the error occurs in the module script

ERROR HERE 17:22:06.288 - LoadAnimation requires the AnimationController object (VM_PLR.A_CT) to be a descendant of the game object

LOCAL SCRIPT HERE

local AnimService = require(game.ReplicatedStorage.ModuleScripts.LoadAnimService)

game.ReplicatedStorage.Events.BindableEvents.PlayerPressedPlay.Event:Connect(function(GunsRequested, GunsRequestedPos)
    local VM = game.ReplicatedStorage.VM_PLR:Clone()
    local fol = Instance.new("Folder", workspace.PlrVM)
    VM.Parent = fol
    local char, plr = game.Players.LocalPlayer.Character, game.Players.LocalPlayer
    fol.Name = plr.Name
    local hum = VM.A_CT
    local c = false
    for i, v in pairs(hum:GetChildren()) do
        if v:IsA("Animator") then
            c = true
            break
        end
    end
    if c == false then
        Instance.new("Animator", hum)
    end
    char.Humanoid.Died:Connect(function()
        VM.Parent = nil;
    end)
    game:GetService("RunService").RenderStepped:Connect(function()
        VM.Head.CFrame = workspace.CurrentCamera.CFrame
    end)
    game.ReplicatedStorage.Events.RemoteEvents.AnimationInfo.OnClientEvent:Connect(function(sett)
        if sett.SWEPBASE == nil then
            print("homie dats nil my brudda")
        else
            print(sett.SWEPBASE)
            if sett.SWEPBASE == "FIST" then
                local a, b = AnimService:LoadAnimTable(game.ReplicatedStorage.Animations.VM_ANIMATIONS.FIST:GetChildren(), hum, VM)
                local Idle = AnimService:DecodeAnimTable(a, b, "Idle")
                local function IdleAnim()
                    Idle.Looped = true
                    Idle:Play()
                end 
                IdleAnim()
            end
        end
    end)
end)

MODULE SCRIPT HERE

local module = {}

function module:LoadAnimTable(tab, hum)
    local ANIMATABLE = {}
    local ANIMATABLEPOS = {}
    for i, v in pairs(tab) do
        table.insert(ANIMATABLE, 1, hum:LoadAnimation(v))
        table.insert(ANIMATABLEPOS, 1, v.Name)
    end
    return ANIMATABLE, ANIMATABLEPOS
end

function module:DecodeAnimTable(animtable, animtablepos, returnval)
    local counter = 1
    local result = nil

    local attempt = table.find(animtablepos, returnval)
    if attempt ~= nil then
        for i, v in pairs(animtable) do
            if counter == attempt then
                result = v
                break
            else
                counter = counter + 1
            end
        end
    end

    return result
end

return module

2 answers

Log in to vote
1
Answered by 4 years ago

It looks like you have a problem playing animations when the viewmodel is set to nil.

Basically, the error is saying the viewmodel has to be in workspace to play the animation. The problem is, you're setting the model's parent to nil. Here's a way you might be able to solve that.

local dead = false

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
    dead = true
    viewmodel.Parent = nil
end)

--//When you're about to play animations do:

if dead == false then --//If we're not dead
    anim:Play() -- play
else --//If we're ded
    print("player is ded")
    delay(2, function() -- Set dead back to false after a bit.
        dead = false
    end)
end

I'm pretty sure this isn't the best way to solve it, but it does the job.

Let me know if you have any issues, questions or concerns.

Cheers, Zander

0
Thanks for the help! Although, I forgot to mention that the error occurs on the module script, which hum:LoadAnimation(v) fails to work. Thank you for helping at least. rookiecookie153 53 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

YES YES YES YES! THE SOLUTION IS TO RESET YOUR SCRIPTS WHEN YOU DIE!!!!

Answer this question