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)
Try this:
local player = game.Players.LocalPlayer local character = player.Character or Player.CharacterAdded:Wait()
Try using that as your character line at the top of your script.
Because for the character, it's looking for the character, and if the script can't find the character from the player it will wait until the character is added to workspace and reference that variable to the character.
If it works, let me know by taking this as an answer. If it doesn't comment below what happens and I'll try to fix it for you!