Script I made won't display custom tool holding animation for a flashlight?

  1. Here’s the code, I had to modify it a tiny bit to fit with the name of the animation:
Code
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local EquipAnim = Tool.Flashlight

local Equip = Character.Humanoid.Animator:LoadAnimation(EquipAnim)

Tool.Equipped:Connect(function()

	Equip:Play()

end)

Tool.Unequipped:Connect(function()

	Equip:Stop()

end)
  1. Nope, right clicked to check out the “Go to Script Error” option in the menu that pops up, and said option was grayed out, no error messages in bottom bar either.
  2. Double checked; animation is indeed set to action.
  3. I put the code in a local script like you said.

Play the game, click F9, and see if there’s any errors in both the client and server section.

Is the owner of the animation you’re trying to play you or someone else?

It’s my animation, one I animated myself; I also animated about 30 other animations for various other tools and character animations.


The server log is empty, but the client log has a bunch of errors. However I don’t see any errors relating to the flashlight in my backpack?

Is this a group game or a game belonging to you?

The only other thing it could be is a wrong id. Maybe try this out?

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local EquipAnim = Tool.Flashlight
local Character,Humanoid,Equip

Tool.Equipped:Connect(function()
	Character = Tool.Parent
	Humanoid = Character.Humanoid
	If not Equip then
		Equip = Humanoid.Animator:LoadAnimation(EquipAnim)
	end
	Equip:Play()
end)

Tool.Unequipped:Connect(function()
	Equip:Stop()
end)
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local offScopeTrack = nil


Tool.Equipped:Connect(function()

local EquipAnim = Tool.Flashlight
local Equip = Character.Humanoid.Animator:LoadAnimation(EquipAnim)
offScopeTrack = Equip
	Equip:Play()

end)

Tool.Unequipped:Connect(function()

	offScopeTrack:Stop()

end)

This should work now, I didn’t specify the path to the tool last time, see if it works.

1 Like

It’s not published yet, still working on it in studio. Will give this script a try, as well as the other one.

1 Like

THIS ONE WORKED!


IT ACTUALLY WORKED!
Hell yes, thank you so much! You all helped a lot.

Sooo I’ve got a new problem. The problem occurs after my player dies…
This is after death…


compared to before…

What’s going on now?

Ok, so, if I am right, you’re equipping the flashlight way too fast, and the animation probably hasn’t loaded yet, so we can try doing the following:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local offScopeTrack = nil


Tool.Equipped:Connect(function()

local EquipAnim = Tool:WaitForChild("Flashlight") --Wields the script until the animation has loaded.
local Equip = Character.Humanoid.Animator:LoadAnimation(EquipAnim)
offScopeTrack = Equip
	Equip:Play()

end)

Tool.Unequipped:Connect(function()

	offScopeTrack:Stop()

end)```


Uhoh.

Details? This happened when you died? after changing the script?

Nope this is after clicking play and holding out the flashlight (after changing the script).

Try to change the “WaitForChild” to “FindFirstChild”

Wait hold on, I think I identified a problem;
there is no line that is defining “tool”…
Anyway I did that and changed the script accordingly…
Upon pressing play and pulling out the flashlight:


And then after dying…

I’m getting confused…

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local offScopeTrack = nil


Tool.Equipped:Connect(function()

local EquipAnim = Tool:WaitForChild("Flashlight") --Wields the script until the animation has loaded.
local Equip = Character.:WaitForChild("Humanoid").Animator:LoadAnimation(EquipAnim)
offScopeTrack = Equip
	Equip:Play()

end)

Tool.Unequipped:Connect(function()

	offScopeTrack:Stop()

end)

Character:WaitForChild("Humanoid").Died:Connect(function()

offScopeTrack:Stop()

end)

This is my last attempt to try and solve the problem.

I’ll get back to this in a few hours, I got other stuff I need to do. When I’m done I will try this out and say how it goes

I’ve had a similar issue with tool animations not working after death but I fixed it by adding a line of code at the top of the script

game:GetService("RunService").Heartbeat:Wait()
1 Like

…Thanks, will add that too. Anyway, I got stuff to do

1 Like