I am trying to make an idle and attack animation for a sword, but when I try to get the animation to run on the humanoid, it won't work saying, "attempt to index field 'Character' (a nil value)." Someone, please assist me on how to fix this problem.
Here's the local script:
local CanAttack = true
local idle = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(script.idle)
local attack = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(script.attack)
script.Parent.Equipped:Connect(function()
idle:Play()
script.Parent.Activated:Connect(function()
if CanAttack then
idle:Stop()
attack:Play()
CanAttack = false
wait(1)
attack:Stop()
idle:Play()
CanAttack = true
script.Parent.CanDamage.Value = true
end
end)
end)

1 comment
From there, you can then reference humanoid from the character by doing local humanoid = character:WaitForChild("Humanoid")