How do you get the character after a player dies in a module script

  1. What do you want to achieve? I want my module script to refresh the humanoid and character.

  2. What is the issue? I use a module script to load the players animations for tools but after the player dies the table does not update the humanoid it uses therefore rendering it useless. I know the table works for animations and the only reason I use it is because if I don’t load it in a universal variable I will have to load a new animation through every script which is going to cause issues.

  3. What solutions have you tried so far? I’ve tried using character adding and updating the character variable and humanoid but I dont think that it updates the table of animations. I’ve also tried putting the table into the character added event but It doesn’t register the table.

Script:

player = game.Players.LocalPlayer
char = player.Character or player.CharacterAdded:Wait()
player.CharacterAdded:Connect(function(character)
char = character
end)
local human = char:WaitForChild(‘Humanoid’)
local animations = {
slide = human.Animator:LoadAnimation(script.SlideAnim),
handgunIdle = human.Animator:LoadAnimation(script.Handgun_Idle),
handgunFire = human.Animator:LoadAnimation(script.Handgun_Fire),
handgunReload = human.Animator:LoadAnimation(script.Handgun_Reload),
jumpKick = human.Animator:LoadAnimation(script.JumpKick),
canSprint = true
}

return animations

Have you tried human.Died function?

Yes it had the same effect as character added.

Pretty sure that the module won’t be able to detect a humanoid’s death at all, so you will have to make a local or server script depending on your module, and make it so the script tells the module when the humanoid died.

Hey I appreciate the help, I ended up just putting a module in the starterCharacterscripts and called it from there haha. It seems to work pretty good that way.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.