I have this tool that if I shift sprint with it, it plays this custom animation I have used, but when I reset, I get this error on Line 22 saying "LoadAnimation requires the Humanoid object (TechModel.Humanoid) to be a descendant of the game object." I don't get why this is happening that when I die and respawn it gives that kind of error output. If there's an alternative script that has better functionality or is suitable/recommended, then please let me know.
What type of script, you ask? It is a Local Script that is in the Tool, and the animation is parented inside the Local Script.
-- Services
local userInputService = game:GetService("UserInputService")
local playersService = game:GetService("Players")
local Player = game.Players.LocalPlayer
-- Variables
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local pcButton = Enum.KeyCode.LeftShift
local xboxButton = Enum.KeyCode.ButtonL3
local IsEquipped = false
local tool = script.Parent
-- Animation
local animation = script:WaitForChild("SprintAnim")
local sprintTrack = humanoid:LoadAnimation(animation)
-- Input controller
userInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == (pcButton or xboxButton) and not processed and IsEquipped then
sprintTrack:Play(.1)
end
end)
userInputService.InputEnded:Connect(function(input, processed)
if input.KeyCode == (pcButton or xboxButton) and not processed then
sprintTrack:Stop(.1)
end
end)
tool.Equipped:Connect(function()
IsEquipped = true
end)
tool.Unequipped:Connect(function()
IsEquipped = false
sprintTrack:Stop(0)
end)

5 comments
No, if its a local script it'll automatically redo the script. Before you start the script simply add a wait(2) then it'll work.
Just a suggestion, don't use humanoid:LoadAnimation(), it's deprecated. try to loadanimtion using the animator found in the humanoid
did @coolfaizan7861's answer work?
Yes it worked because him adding that wait and me resetting works just fine.
alr cool.