Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation not working with a tool equipped?

I'm trying to make a swing animation for a sword, but the animation isn't working on the hand that the tool is equipped on.

Local Script:

script.Parent.Equipped:Connect(function()

local Tool = script.Parent
local Animation = Tool.Animation
local Character = Tool.Parent
local Humanoid = Character.Humanoid
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()

end)
end)

1 answer

The LoadAnimation function of Humanoid was deprecated. It's recommended you call this method on the new Animator:

####I have also made some efficiency changes.

--###----------[[SERVICES]]----------###--
local Players = game:GetService("Players")



--###----------[[VARIABLES]]----------###--
local Player = Players.LocalPlayer


local Tool = script.Parent



--###----------[[FUNCTIONS]]----------###--
local function OnActivated()
	local Character = Player.Character
	if (Character) then
		---------------
		local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
		if (Humanoid and Humanoid.Health > 0) then
			---------------
			Humanoid.Animator:LoadAnimation(Tool.Animation):Play()
		end
	end
end



--###----------[[SETUP]]--------###--
Tool.Activated:Connect(OnActivated)

3 comments

0

This didn't fix my problem. My problem was that the animation wouldn't play on the hand that I had the tool equipped on. I also tried your solution and it didn't work.

0

What priority is the animation under?

0

It was core, so I just changed it to action and it work. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.