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
01 | local AnimService = require(game.ReplicatedStorage.ModuleScripts.LoadAnimService) |
02 |
03 | game.ReplicatedStorage.Events.BindableEvents.PlayerPressedPlay.Event:Connect( function (GunsRequested, GunsRequestedPos) |
04 | local VM = game.ReplicatedStorage.VM_PLR:Clone() |
05 | local fol = Instance.new( "Folder" , workspace.PlrVM) |
06 | VM.Parent = fol |
07 | local char, plr = game.Players.LocalPlayer.Character, game.Players.LocalPlayer |
08 | fol.Name = plr.Name |
09 | local hum = VM.A_CT |
10 | local c = false |
11 | for i, v in pairs (hum:GetChildren()) do |
12 | if v:IsA( "Animator" ) then |
13 | c = true |
14 | break |
15 | end |
MODULE SCRIPT HERE
01 | local module = { } |
02 |
03 | function module:LoadAnimTable(tab, hum) |
04 | local ANIMATABLE = { } |
05 | local ANIMATABLEPOS = { } |
06 | for i, v in pairs (tab) do |
07 | table.insert(ANIMATABLE, 1 , hum:LoadAnimation(v)) |
08 | table.insert(ANIMATABLEPOS, 1 , v.Name) |
09 | end |
10 | return ANIMATABLE, ANIMATABLEPOS |
11 | end |
12 |
13 | function module:DecodeAnimTable(animtable, animtablepos, returnval) |
14 | local counter = 1 |
15 | local result = nil |
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.
01 | local dead = false |
02 |
03 | game.Players.LocalPlayer.Character.Humanoid.Died:Connect( function () |
04 | dead = true |
05 | viewmodel.Parent = nil |
06 | end ) |
07 |
08 | --//When you're about to play animations do: |
09 |
10 | if dead = = false then --//If we're not dead |
11 | anim:Play() -- play |
12 | else --//If we're ded |
13 | print ( "player is ded" ) |
14 | delay( 2 , function () -- Set dead back to false after a bit. |
15 | dead = false |
16 | end ) |
17 | 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
YES YES YES YES! THE SOLUTION IS TO RESET YOUR SCRIPTS WHEN YOU DIE!!!!