Need help with a sword animation script

  1. What do you want to achieve? Keep it simple and clear!
    A sword that can do animations
  2. What is the issue? Include screenshots / videos if possible!
    My code is supposedly written the correct way, but I cant index an humanoid.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    None were there

Local script

local Character = game:GetService("Players").LocalPlayer.Character
local Tool = script.Parent
local LSHOLDANIM = Tool:WaitForChild("LSHOLD")
local LSSwing1 = Tool:WaitForChild("LSSwing1")
local Equipped = false
local Debounce = false
-- Load anims
local Swing1 = Character.Humanoid:LoadAnimation(LSSwing1)
local LSHold = Character.Humanoid:LoadAnimation(LSHOLDANIM)
-- Tool equipped
Tool.Equipped:Connect(function()
	Equipped = true
	LSHold:Play()
end)
Tool.Unequipped:Connect(function()
	Equipped = false
	LSHold:Stop()
end)

Tool.Activated:Connect(function()
	if Debounce == false and Equipped then
		Debounce = true
		Swing1:Play()
	end
end)

Error Message: " Players.justin2710.Backpack.LongSword.LocalScript:10: attempt to index nil with ‘Humanoid’ "

Try this:


local Swing1 = Character:WaitForChild(“Humanoid”):LoadAnimation(LSSwing1)
local LSHold = Character:WaitForChild(“Humanoid”):LoadAnimation(LSHOLDANIM)

I assume that your LocalScript is located in StarterPack so it errors because it loads faster than the character’s Humanoid.

I suggest making a reference like this:

local Humanoid = Character:WaitForChild(“Humanoid”)

Just so you don’t have to write “ Character:WaitForChild(“Humanoid”)” every time and it guarantees the Humanoid is loaded.