Animation script not Working

local UIS = game:GetService("UserInputService")
local M1Swing1 = script.Parent-- animation

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		print("user pressed E")
		
		local player  = game.Players.LocalPlayer
		local char = player.Character
		local hum = char.Humanoid 
		
		local M1Swing1Track = hum:LoadAnimation(M1Swing1) 
		M1Swing1Track:Play()-- making the track
		print("Script Worked")
	end
end)

Screenshot 2021-07-07 134239
All the prints ran successfully and I have no output error. The issue is that the animation would not load.

1 Like

You shouldn’t use LoadAnimation as it is deprecated.

Oh ok , but what else should I use.

try this

local UIS = game:GetService(“UserInputService”)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then

	local player = game.Players.LocalPlayer
	local Animate 
	local Humanoid = player.Character:FindFirstChild('Humanoid')
	local Animation = Instance.new("Animation", player.Character)
	
	Animation.AnimationId = "rbxassetid://" -- your animationid
	Animate = Humanoid:LoadAnimation(Animation)
	Animate:Play()

end

end)

LoadAnimation is not deprecated. Calling LoadAnimation on the humanoid is deprecated. You should use this function on the Animator object.

1 Like

Mistake, humanoid:LoadAnimation is deprecated. try animator:LoadAnimation instead:

local function playAnimationFromServer(character, animation)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- need to use animation object for server access
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack:Play()
			return animationTrack
		end
	end
end
1 Like

also make sure to put this local script in starterplayer.startercharacterscripts