Animation script not working

I tried to make a script that fires the animation when ever we click, but it does not work
This is the script

local tool = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8058798658"
local track 
tool.Activated:Connect(function()
	track = script.Parent.Humanoid.LoadAnimation(animation)
	track.Priority = Enum.AnimationPriority.Action
	track.Looped = false
	track:Play()
	
end)
tool.Unequipped:Connect(function()
	if track then
		track:Stop()
	end
end)

This is the error that is displaying,What could be the problem here?

The script you’re showing us now… is it your LocalScript?
If so, try

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8058798658"
local track 
tool.Activated:Connect(function()
	track = humanoid:LoadAnimation(animation)
	track.Priority = Enum.AnimationPriority.Action
	track.Looped = false
	track:Play()
end)
tool.Unequipped:Connect(function()
	if track then
		track:Stop()
	end
end)

If the code you sent us is NOT the LocalScript, please send us the code for the LocalScript.

Uhm yep it is a localscript and let me try that real quick

Uhm lol it works but I animated it for the wrong hand so cant you make it so that the default player hand in left hand?,Thanks by the way

Hilariously enough, this is a very difficult task to accomplish. Roblox tools are supposed to be held in the right hand by default. In order for you to switch the hands, you would have to take advantage of some CFrame mechanics and physics constraints, which is very complex.

My apologies.

No problem I can understand thanks by the way I will just change the animation for right hand

1 Like