How do i make a tool play animation when holding mouse2

The title says what i am trying to accomplish , but it gives
Humanoid is not a valid member of Player “Players.CENABOOSS” which is my name
how do i fix it
below is the code used
animation id is child of the script and tool is the parent of the script

local player = script.Parent.Parent.Parent
local humanoid =player.Humanoid
local UIS = game:GetService("UserInputService")
local anim = script:WaitForChild("Animation")
local animTrack = humanoid.Animator:LoadAnimation(anim)
animTrack = humanoid:LoadAnimation(anim)


UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		animTrack:Play()
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Mouse2 then
		animTrack:Stop()
	end
end)
2 Likes

I see the mistake here! you need to do

player.Character.Humanoid
2 Likes

Humanoid can only be found inside the character. In your code you’re getting the humanoid from the player which isn’t possible. You need to mention the character first to get the humanoid as Danki said.

2 Likes

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