Help with my animation!

Hello everyone! Recently, I wrote some code: when you click a button, an animation should play, but it doesn’t work. I can’t find the mistake. I need help!

local gui = script.Parent.Parent
local button = gui.anim.TextButton

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local hitAnim = Instance.new("Animation")
hitAnim.AnimationId = "rbxassetid://71954684660095"
local hitTrack = humanoid:LoadAnimation(hitAnim)

button.MouseButton1Click:Connect(function()
	hitTrack:Play()
	print("Anim is started!")
end)

HI!! seems like you didnt show us the error message from the console, What is the error message?

There isn’t error message, but the animation just doesn’t play.

where is the script and the button located? can you please screen shot the localscript location and the gui location?


here

Are you sure that the animation IS IN R15 and NOT IN R6?

I don’t understand you a bit!!!

try this code now, It should theoretically work

local button = script.Parent.TextButton

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

button.MouseButton1Click:Connect(function()
	
	local s, er = pcall(function()
		local hitAnim = Instance.new("Animation")
		hitAnim.AnimationId = "rbxassetid://71954684660095"
		local hitTrack = humanoid:LoadAnimation(hitAnim)
		
		hitTrack:Play()
	end)
	
	if s then print("Anim is started!") elseif not s then warn(er) end
end)

and if something’s wrong it’d tell you the issue

is the animation for R6 or for R15… maybe the animation dont support R15, so try changing your character to R6

i will try it now!!!

You are missing the animator part. Below is an example, make sure you load your animation into the animator of the Humanoid.

-- Create a new "Animation" instance and assign an animation asset ID

local kickAnimation = Instance.new("Animation")

kickAnimation.AnimationId = "rbxassetid://2515090838"

-- Load the animation onto the animator

local kickAnimationTrack = animator:LoadAnimation(kickAnimation)