What's wrong with my animation script?

Hello, I’m making animations UI when player clicks the button it they will start dancing but I can’t find any bug in the script or errors in output, here’s script:

Script

local button = script.Parent
local animation = script.Animation
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild(“Humanoid”)

playing = false

local function PlayDance()
local playerDance = humanoid:LoadAnimation(animation)
if playing == false then
playerDance:Play()
playing = true
print(“Starting Animation!”)
elseif playing == true then
playerDance:Stop()
playing = false
print(“Stoping animation!”)
end
end

button.MouseButton1Click:Connect(PlayDance)

Also here’s explorer part image
What you think where’s my mistake?

This is deprecated. Just load your animation on the animator, read here.

animator:LoadAnimation()

Example:

local animator = humanoid:FindFirstChildOfClass("Animator")
	if animator then
		local animationTrack = animator:LoadAnimation(animation)
		animationTrack:Play()
1 Like

Thank you it’s working fine now!

1 Like