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

why cant the animation play when I equipp the tool, after I die?

When I join the game Im able to equip my sword that does a little animation. But when I die and re - equip the sword, I cant do the animation any more when I equip it... the error is here below...

"17:50:08.389 - LoadAnimation requires the Humanoid object (Tizzel40.Humanoid) to be a descendant of the game object"

I dont understand why. When equipped, you should do a simple animation, every time, no matter what if you die.

--- This script Only alwos you to do the animation only if you dont die. However, If you do die, the whole script gives an error...

here is the script (The Problem is on lines 13 - 18)

local Remote = script.Parent:WaitForChild("Remotes").damage

local play = game.Players.LocalPlayer

local character = play.Character or play.CharacterAdded:wait()

  

local use = false

  

local hum = character:WaitForChild("Humanoid")

  

local attackvalue = 1

  

  

local idleanim = hum:LoadAnimation(script.Parent:WaitForChild("Animations").Idle)

local eqipinganim = hum:LoadAnimation(script.Parent:WaitForChild("Animations").equipped)

  

script.Parent.Equipped:Connect(function()

eqipinganim:Play()

end)

  

  

  

  

script.Parent.Activated:Connect(function()

local Damage = math.random(100,110)

local char = play.Character

local attacken = char:WaitForChild("CanAttack")

------------if play.Character.ShieldPoints.Value == 0 then

print("no swing")

  

if attackvalue == 1 then

if use == false and attacken.Value == true then

use = true

attackvalue = 2

print("swing")

local hitanim = script.Parent:WaitForChild("Animations").Attack1

local hitplay = play.Character.Humanoid:LoadAnimation(hitanim)

hitplay:Play()

Remote:FireServer(Damage)

  

wait(.4)------------cooldown number

use = false

end

elseif attackvalue == 2 then

if use == false and attacken.Value == true then

use = true

attackvalue = 3

print("swing2")

local hitanim = script.Parent:WaitForChild("Animations").Attack2

local hitplay = play.Character.Humanoid:LoadAnimation(hitanim)

hitplay:Play()

Remote:FireServer(Damage)

  

wait(.5)------------cooldown number

use = false

  

  

end

elseif attackvalue == 3 then

if use == false and attacken.Value == true then

use = true

attackvalue = 1

print("swing2")

local hitanim = script.Parent:WaitForChild("Animations").Attack3

local hitplay = play.Character.Humanoid:LoadAnimation(hitanim)

hitplay:Play()

Remote:FireServer(Damage)

  

wait(.7)------------cooldown number

use = false

  

end

end

----end

end)

  

  

  

--scripted by Tizzel40

1 comment

0

In the future, paste your code in as regular text first and then select it and hit the code block button. It has less of a chance to lose indentation and almost no chance for the spacing to break.

1 answer

In order to load animations, the character must be in the workspace.

Today, ROBLOX made improvements on how avatar loading works: https://devforum.roblox.com/t/avatar-loading-event-ordering-improvements/269607

As you see in Event Changes, CharacterAdded fires before the Character actually gets parented to the workspace. Reading it further down, you can fix it by adding this if statement:

if  not character.Parent then
    character.AncestryChanged:wait()
end

You could also be inefficient and us a loop that waits until the character's parent is in the workspace, but I don't recommend it if you want to become a better scripter.

Good luck!

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