Play Animation On Click

Today I was making a game where all you do is cry and I want to make a button that you can click and my animation will play. I’ve tried


local de = true

script.Parent.MouseButton1Click:Connect(function(player)

wait(3)

local Animation = player.Character.Humanoid:LoadAnimation(script.Parent.Cry)

if de == true then

de = false

Animation:Play()

end

wait(5)

de = true

end)
But it just keeps erroring Players.BMWLux.PlayerGui.ScreenGui.TextButton.LocalScript:4: attempt to index nil with 'Character'.

There is no parameter for MouseButton1Click, so you can’t get the player from it. Try the following:

local player = game.Players.LocalPlayer
local de = true

script.Parent.MouseButton1Click:Connect(function()

wait(3)

local Animation = player.Character.Humanoid:LoadAnimation(script.Parent.Cry)

if de == true then

de = false

Animation:Play()

end

wait(5)

de = true

end)

Wait there isn’t?! Thats crazy! I thought there was XD Ill try out that script. Local player of course.

1 Like

Error: LoadAnimation requires an Animation object. Im confused because it is a r6 animation.

What is script.Parent.Cry. You have to load an animation using an animation ID.

It has all the keyframes and stuff under the animation.

Oh ok I see! Ill just find the anim id.

Yes. It should be like:

local Animation = player.Character.Humanoid:LoadAnimation(123456789)

local player = game.Players.LocalPlayer
local de = true

script.Parent.MouseButton1Click:Connect(function()

wait(3)

local Animation = player.Character.Humanoid:LoadAnimation(6228208026)

if de == true then

	de = false

	Animation:Play()

end

wait(5)

de = true

end)

1 Like

Unable to cast value to Object. What does this mean?

Never mind, I think what I told you was incorrect about using the Animation Id. What you had before I think was correct. So script.Parent.Cry is an “Animation”?

Yeah it is. Let me test 1 more time.

Now its erroring again LoadAnimation requires an Animation object…

Thats strange. Can I see a screen shot of the explorer.

Sure! How do I take a screenshot XDD

Let me try something out rq. Brb.

Idk how you do it on Windows, but if you are on Mac it is Command + Shift + 4

just do prt sc on your keyboard

1 Like