When click tool does animation problem

5th day of scripting :slight_smile:

  1. What do you want to achieve? Keep it simple and clear!

I’d like that when I click my tool, my character would do an animation.

  1. What is the issue? Include screenshots / videos if possible!

I’m having difficulties with putting the animator in the humanoid of the player that has the tool.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I went a bit in circles yesterday forgot what I did x)

local tool = script.Parent


local Players = game:GetService("Players")

print("0")
tool.Equipped:Connect(function(player)
	
	print("1")
	
	
	local Humanoid = player:WaitForChild("Humanoid") -- it's saying that the character doesn't exist?
	print("2")

	local Animator= Humanoid:WaitForChild("Animator")



	local AnimationB= Instance.new("Animation")

	AnimationB.AnimationId= "rbxassetid://12895335221"
	
	local AnimationBTrack = Animator:LoadAnimation()
	
	tool.Activated:Connect(function()
		



		
		AnimationBTrack:Play()
		
		end)	
end)

where my script is
image

Also apparently a localscript is needed because this only affects one player?

The Output:

I think I see the issue, give me a few minutes to rewrite the code.

Equipped returns the player’s mouse, not a player instance, since this is a local script, you can do

local player = Players.LocalPlayer

tool.Equipped:Connect(function()

outside the event and then do player.Character:WaitForChild("Humanoid") to get the humanoid

Also, I wouldn’t recommend putting the activated event inside of the equipped event, as it would make as many events as you equip the tool (If you equip the tool 5 times, you’ll have 5 activated events). Place it outside and make AnimationBTrack be outside the equipped event

local AnimationBTrack

-- Then in your equipped event

AnimationBTrack = Animator:LoadAnimation(AnimationB)
1 Like

Thanks, lol.

Made my job a bit easier!

1 Like

thanks, I was using equipped event because I was searching where the bug was.

I guess I can just put all the variables outside and keep

AnimationBTrack:Play()

when the tool is clicked, I’ll update the code and teel you if it works !

I got this message of error.

local tool = script.Parent


local Players = game:GetService("Players")

local player= Players.LocalPlayer

print("0")

	
print("1")
	
	
local Humanoid = player.Character:WaitForChild("Humanoid") -- it's saying that the character doesn't exist?
print("2")

local Animator= Humanoid:WaitForChild("Animator")


local AnimationB= Instance.new("Animation")

AnimationB.AnimationId= "rbxassetid://12895335221"
	
local AnimationBTrack = Animator:LoadAnimation()

	
tool.Activated:Connect(function()
	AnimationBTrack:Play()

end)

It’s because you didn’t give time for the character to exist. I think keeping the Equipped event is good, there wasn’t any issue with it

1 Like

I do not understand

local tool = script.Parent


local Players = game:GetService("Players")

local player= Players.LocalPlayer


tool.Equipped:Connect(function()
	
	local Humanoid = player.Character:WaitForChild("Humanoid") -- it's saying that the character doesn't exist?
	
	print("2")

	local Animator= Humanoid:WaitForChild("Animator")


	local AnimationB= Instance.new("Animation")

	AnimationB.AnimationId= "rbxassetid://12895335221"


end)

local AnimationBTrack = Animator:LoadAnimation()



tool.Activated:Connect(function()
	AnimationBTrack:Play()

end)

Ima fully redo the code it’s kinda weird how I did it

try doing as I mentioned here for the AnimationBTrack, put local AnimationBTrack outside the equipped event and then place Animator:LoadAnimation(AnimationB) in the variable inside of the Equipped event

1 Like

Very long thread.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid:Humanoid? = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid",25)
local Animator:Animator? = Humanoid:FindFirstChildOfClass("Animator") or Humanoid:WaitForChild("Animator",25)
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://12895335221"
Animation.Parent = script.Parent
local Anim = Animator:LoadAnimation(Animation)
local Tool = script.Parent

Tool.Activated:Connect(function()
	Anim:Play()
end)

I missread at first ty very much for your time :slight_smile:

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