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.
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.
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
Also apparently a localscript is needed because this only affects one player?
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)
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)
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)
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
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)