Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Animations in Tools Breaking After Death?

When creating a tool, I inserted some animations and a few lines related to animation playing/loading. It works fine when I test it, but when I reset, the output says this: LoadAnimation requires the Humanoid object (Sensei_Developer) to be a descendant of a game object

Here's my LocalScript inside of one of the tools:

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')

local Food_Hold = humanoid:LoadAnimation(script.Parent.Food_Hold)
local Food_Interact = humanoid:LoadAnimation(script.Parent.Food_Interact)

script.Parent.Equipped:Connect(function()
	Food_Hold:Play()
	script.Parent.Handle.Equip:Play()
end)
script.Parent.Unequipped:Connect(function()
	Food_Hold:Stop()
	Food_Interact:Stop()
	script.Parent.Handle.Equip:Stop()
end)
local CanInteract = true
script.Parent.Activated:Connect(function()
	if CanInteract == true then
		script.Parent.Handle.Eating:Play()
		CanInteract = false
		Food_Interact:Play()
		wait(1.5)
		Food_Interact:Stop()
		CanInteract = true
	end
end)

Other scripts inside of the tools are similar to this.

Can anyone help me? I feel like there's something wrong with the variables I defined.

2 answers

✓ Accepted answer

When a player dies, their character model is destroyed along with their humanoid and a new one is created when they respawn. The humanoid you defined is the one created when they join the game, but this humanoid doesn't exist anymore after the player has respawned. To fix this, you could put it all in a player.CharacterAdded:Connect(function(character) end) function. This event fires everytime the character model is added to the game, so every time the player respawns. You could load the animation to the new humanoid every time this event is fired instead of just once.

1 comment

0

Ty.

Everytime a player dies they are given a new humanoid. So the script is still trying to find the previous humanoid that was parented to the player. Essentially what your going to want to do is add a characteradded event. It basically fires everytime the players character is added into the game.

player.CharacterAdded:Connect(function(char)

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.