I am trying to make an idle animation stop but when I put in Character:FindFirstChild("Humanoid") it says "20:48:14.460 - Players.360gamer107.Backpack.Desteller.LocalScript:72: attempt to index local 'Humanoid' (a nil value)" The problem is on lines 69 - 77.
local debounce = false
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
ValueCooldown = false
function SwordCore(hit)
local Enemys = hit.Parent:FindFirstChildOfClass("Humanoid")
if script.CanDamage.Value and Enemys then
local EnemyHit = hit.Parent:FindFirstChild("Enemy")
local PlayerHit = hit.Parent:FindFirstChild("Humanoid")
local Character = Tool.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
if (not Player) then return end
local Humanoid = Character:FindFirstChild("Humanoid")
if (not Humanoid) then return end
if Enemys ~= Humanoid and (not debounce) then
if Enemys.Health <= 0 then return end
debounce = true
if PlayerHit then
game.ReplicatedStorage.PlayerHit:FireServer(hit,PlayerHit,Tool)
end
if EnemyHit then
game.ReplicatedStorage.EnemyHit:FireServer(hit,EnemyHit,Tool)
end
wait(1)
debounce = false
end
end
end
local on = 1
local timer = tick()
function onActivated()
if (not Tool.Enabled) then return end
Tool.Enabled = false
if tick()-timer >2 then
on = 1
end
timer = tick()
local Character = Tool.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
local Anim = Humanoid:LoadAnimation(Tool["Slash".. on])
local SlashSound = Handle:WaitForChild("SlashSound")
if (Humanoid == nil) then return end
SlashSound:Play()
Anim:Play()
Tool.Unequipped:Connect(function()
Anim:Stop()
end)
on = on + 1
if on >= 4 then
on = 1
end
wait(0.5)
Tool.Enabled = true
end
function onEquipped()
local Character = Tool.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
local Idle = Humanoid:LoadAnimation(Tool.Idle)
if (not Tool) then return end
if (not Handle) then return end
Idle:Play()
if Handle.UnsheathSound.IsPlaying == false then
Handle.UnsheathSound:Play()
end
end
function onUnEquipped()
local Character = Tool.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
local Idle = Humanoid:LoadAnimation(Tool.Idle)
if (not Tool) then return end
if (not Handle) then return end
Idle:Stop()
Handle.UnsheathSound:Stop()
end
function checkValue()
if ValueCooldown == false then
ValueCooldown = true
script.CanDamage.Value = true
wait(1)
script.CanDamage.Value = false
ValueCooldown = false
end
end
Tool.Activated:Connect(onActivated)
Tool.Activated:Connect(checkValue)
Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnEquipped)
Handle.Touched:Connect(SwordCore) ``

1 comment
:(