I’m trying to load animations from the tool into the players humanoid. This works fine, until the player dies. When they die, I get these two errors:
LoadAnimation requires the Humanoid object (Towren.Humanoid) to be a descendant of the game object
Anims is not a valid member of Tool “Players.Towren.Backpack.HK416”
Same errors get thrown for all the other weapons too. Full script:
local maxAmmo = 30
local Ammo = maxAmmo
local reloading = false
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local textLabel = playerGui:WaitForChild("HK416Ammo"):FindFirstChild("AmmoText")
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Anims:FindFirstChild("Reload"))
local holdAnim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Anims:FindFirstChild("Hold"))
script.Parent.Equipped:Connect(function(Mouse)
holdAnim:Play()
textLabel.Parent.Enabled = true
local function reload()
local reloadSound = Instance.new("Sound")
reloadSound.SoundId = "rbxassetid://144798533"
reloadSound.Parent = script.Parent
reloadSound.Playing = true
reloadSound.PlaybackSpeed = 1.5
reloading = true
animation:Play()
wait(2.5)
Ammo = maxAmmo
reloading = false
end
script.Parent.Activated:Connect(function()
if Ammo > 0 and not reloading then
Ammo = Ammo - 1
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://168143115"
sound.Parent = script.Parent
sound.Playing = true
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, 15)
end
elseif reloading == false then
reload()
end
while wait() do
textLabel.Text = (Ammo).." / "..maxAmmo
end
end)
local input = game:GetService("UserInputService")
input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R and reloading == false and Ammo ~= maxAmmo then
reload()
end
end)
end)
script.Parent.Unequipped:Connect(function()
holdAnim:Stop()
textLabel.Parent.Enabled = false
end)
Anyone got any solutions? Really bugging me.