Tracks not loading

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

https://gyazo.com/e1057c7e500ee9c172f45cd6d296c645

I really have no idea what causes this but I have break joints set to false

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.

Just found what you said is true it’s using the old humanoid that resetted but there is no way to reference the newer one?

also some why another tool gets the correct humanoid…

You could just do this:

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

I do this now, but this is bad cause it causes delay at first equip, I used to load it pre-tool equip

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

whenever a tool spawns Player.Character is set to the older character

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:


<AnimationTrack>.Priority = Enum.AnimationPriority.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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.