Tool equip script is not working

I want an animation to play when I pick up the tool. These are my codes:

local tool = script.Parent
local anim = tool.Animation2
local oyuncu = game:GetService("Players").LocalPlayer
local char = oyuncu.Character
local humanoid = char:WaitForChild("Humanoid")
local loadanim = humanoid:LoadAnimation(anim)

function aldi()
	loadanim:Play()
end

tool.Equipped:connect(aldi)


But my codes are not working. I want help with this.

Trivial, but apparently Humanoid:LoadAnimation() is deprecated, there is an Animator child under it though, which can load animations instead.

Can’t be the issue of a LocalScript, since it will eventually be descendant of Backpack:

you need to do humanoid.Animator:LoadAnimation(anim). humanoid:LoadAnimation() is deprecated.

1 Like

Okay so, maybe the oyuncu.Character is coming back as nil? so maybe try waiting for the Character to spawn. (this may not be the issue since i know it might’ve errored)

local char = Player.Character or Player.CharacterAdded:Wait()

if Player.Character is nil it will wait for the Player.CharacterAdded event to fire.

also make sure the Animation AnimationPriority is set to action or something that can override the player’s character current playing animations (like walking, idle and etc). you change it in the animation editor. is this your animation? if not, try testing it on roblox not on roblox studio play testing.

Hello there!

First of all, the connect function is deprecated. Capitalize the first letter.

tool.Equipped:Connect(aldi)

Second, the LoadAnimation function, which is connected to the humanoid of the character, is deprecated, as the others mentioned. Use it with the Animator.

And make sure the RequiresHandle property of the tool is set to false.

Finally, as @mike00401 suggested, define the character as he said. If the first one had not found the character, the second would have been used. And if not second, the first one. This is a better way to get it without any errors.

1 Like

you need to disable requirehandle on tool property

1 Like
local tool = script.Parent
local anim = tool.Animation2
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local loadanim = animator:LoadAnimation(anim)

tool.Equipped:Connect(function()
	loadanim:Play()
end)

I understood thank you. But still not working :frowning:

Are you getting any errors on the Output?

Heres how mine works (it still works)

--Player Variables
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

--Tool & Animation
local tool = script.Parent
local animation = tool:WaitForChild("Equip1") --Change this to your animation name

local Humanoid = Character:WaitForChild("Humanoid")
local equipAnim = Humanoid:LoadAnimation(animation)

tool.Equipped:Connect(function()
	equipAnim:Play()
end)

tool.Unequipped:Connect(function()
	equipAnim:Stop()
end)

Let me know if any help needed :slight_smile:

Thanks, but it still didn’t work :frowning: is there a setting I should do?

Are you sure you have the correct animation ID? Let us know the animation where it comes from. What is the animation ID?

And also add print wherever you want so you can find the error where it occurs.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

print("Character is found")

--Tool & Animation
local tool = script.Parent
local animation = tool:WaitForChild("Animation2")

print("Animation is found")

local Humanoid = Character:WaitForChild("Humanoid")
local equipAnim = Humanoid:LoadAnimation(animation)

print("Animation is loaded")

tool.Equipped:Connect(function()
    print("Equipped")
    equipAnim:Play()
end)

tool.Unequipped:Connect(function()
    print("Unequipped")
    equipAnim:Stop()
end)

What priority is your animation in?
it won’t work if it not in “Action” priority. You can change it by:

  1. If you haven’t deleted the dummy you made animation in, you can animate it again and the previous animation will show and just change priority and export it again
  2. If not remake animation with Action priority
    Have a nice day!

You cant use LoadAnimation it’s deprecated.

How does mine work then? (Also I feel like the way using animator is deprecated coz it never worked out for me)

LoadAnimation is deprecated on the Humanoid. The superseded method is by using LoadAnimation on the Animators Instance which is a child of Humanoid