I’ve used the :LoadAnimation() function many times before, but today I’m not entirely sure why it’s not working. When I test out the script, I get the error below saying attempt to index nil with ‘LoadAnimation()’. If you can help me out I would very much appreciate it, btw, everything is inside a LocalScript.
That shouldn’t be an issue. I’ve turned the humanoid into a variable and it worked. Also, I can clearly see you post. You don’t want to clog up a topic with repeated posts.
Always use :WaitForChild() when getting stuff inside the character. This is because sometimes, the character does not load in properly, therefor causing your script to completely break.
Instead of FindFirstChild(“Humanoid”) use WaitForChild() and see if anything changes.
I have the same error but :Waitforchild() doesn’t work… does anyone have a solution?
local player = game.Players.LocalPlayer
local Char = player.Character
local Humanoid = Char:WaitForChild("Humanoid")
local AttackAnim = Humanoid:LoadAnimation(SECRET)
AttackAnim.Priority = Enum.AnimationPriority.Action
AttackAnim.Looped = false
local OneShot = Humanoid:LoadAnimation(SECRET)
OneShot.Priority = Enum.AnimationPriority.Action
OneShot.Looped = false
local Sword = script.Parent
local blade = Sword.Handle.Blade
local Cooldown = 2 -- in seconds
local db = true
Sword.Activated:Connect(function()
if db then
db = false
AttackAnim:Play()
blade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if hit.Parent:GetAttribute("Enemy") then
hit.Parent.Humanoid.Health -= 10
print(hit.Parent.Humanoid)
end
end
end)
end
wait(Cooldown)
db = true
end)
local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local AttackAnim = Humanoid:LoadAnimation(SECRET)
AttackAnim.Priority = Enum.AnimationPriority.Action
AttackAnim.Looped = false
local OneShot = Humanoid:LoadAnimation(SECRET)
OneShot.Priority = Enum.AnimationPriority.Action
OneShot.Looped = false
local Sword = script.Parent
local blade = Sword.Handle.Blade
local Cooldown = 2
local db = true
Sword.Activated:Connect(function()
if db then
db = false
AttackAnim:Play()
local conn
conn = blade.Touched:Connect(function(hit)
local targetHum = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if targetHum and hit.Parent:GetAttribute("Enemy") then
targetHum.Health -= 10
print(targetHum)
end
end)
end
wait(Cooldown)
db = true
end)