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

1 comment
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.