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

How can I get this animation to play when I click?

Here's my script:

local Mouse = game.Players.LocalPlayer:GetMouse()
local anime = script.Animation

Mouse.Button1Down:Connect(function()
	print("IT WORKED")
	anime:Play()
end)

It worked until I added the animation:Play()

1 comment

0

You need to load the animation to the Animator (character.Humanoid.Animator) not the HUMANOID because that is deprecated. And then you have to make the loaded one like this local thing = humanoid.Animator:LoadAnimation(anime) and then you can do thing:Play()

2 answers

You gotta load the animation in the humanoid.

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


anime:Play()

7 comments

0

It doesn't work, I keep getting this error: LoadAnimation requires an Animation object

0

Oh oops, I meant script.Animation not script.Parent

0

That didnt work either It just says: Animation is not a valid member of LocalScript "Workspace.(My name).LocalScript"

0

It probably didn't load yet. try script:WaitForChild("Animation")

0

Its still doesnt work but we are getting somewhere because I dont get the error until I click. Right now the error i get is:Play is not a valid member of Animation "Workspace.Paczki_TCBC.LocalScript.Animation"

0

welp im all out of ideas

0

its ok

use :LoadAnimation([Animation]) and put script to StarterCharacterScripts

local Mouse = game.Players.LocalPlayer:GetMouse()
local anime = script.Animation

Mouse.Button1Down:Connect(function()
    script.Parent.Humanoid:LoadAnimation(anime):Play()
end)

1 comment

0

humanoid:LoadAnimation() is deprecated so its not reccomended, you should try humanoid.Animator:LoadAnimation()

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