I have a tool that does something and I play animations if it’s equipped it works fine on the first run but if the player dies while holding it and character resets the track doesn’t play, no errors
local Hold_AnimID = script:WaitForChild("Hold")
local Hold_Track:AnimationTrack = Humanoid:LoadAnimation(Hold_AnimID)
Tool.Equipped:Connect(function()
Hold_Track:Play()
end)
Tool.Unequipped:Connect(function()
Hold_Track:Stop()
end)
This is not the full script, but this is the main thing
The issue you’re facing might be because you’re trying to play the animation on the old humanoid (which died). Not sure if that’s it or not but you might want to define the Humanoid inside of Tool.Equipped
If I do define that I need to load new tracks which has a delay I am printing on top of every tool script to output “init” if it resetted the script and it does.
local Hold_Anim = script:WaitForChild("Hold")
local Hold_Track
Tool.Equipped:Connect(function()
local character = Tool.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
Hold_Track = humanoid:LoadAnimation(Hold_Anim)
Hold_Track:Play()
end
end)
Tool.Unequipped:Connect(function()
if Hold_Track then
Hold_Track:Stop()
Hold_Track:Destroy()
Hold_Track = nil
end
end)
I’m not great with animations myself but something like that should work
Ohh, I now get what you mean
In this case, you could use the player.CharacterAdded event to define the new Humanoid and pre-load the animation on the new Humanoid as soon as he respawns
I don’t know how to help you, might want to revise your code and check for possible mistakes or take another route to how it works or wait for another response, sorry!
Make sure you are loading the track on a Humanoid that still exists (if the humanoid didn’t get destroyed through dying) or try setting the AnimationTrack’s AnimationPriority to Action:
if you want not delay it, you can do something like this:
--Assume this is a local script
--VARIABLES--
local Hold_Anim = script:WaitForChild("Hold")
local Hold_Track
local humanoid
--SERVICES--
local PlayersService = game:GetService("Players")
local player = PlayersService.LocalPlayer
local function ConnectTools(Tool)
Tool.Equipped:Connect(function()
if humanoid then
Hold_Track = humanoid:LoadAnimation(Hold_Anim)
Hold_Track:Play()
end
end)
Tool.Unequipped:Connect(function()
if Hold_Track then
Hold_Track:Stop()
Hold_Track:Destroy()
Hold_Track = nil
end
end)
end
player.CharacterAdded:Connect(function(Character)
humanoid = Character:WaitForChild("Humanoid")
ConnectTools(Tool)
end)
This is faster, because you dont get humanoid every time. Only once. And then its cached so you can access it.
IMPORTANT
Loading animations on humanoid is deprecated, I recommend you use Animator which is under Humanoid.