Animation Scripting Support

local HandsUpAnimation = game.Workspace.HandsUp
local Humanoid = game.Players.LocalPlayer:WaitForChild("Humanoid")
local PlayAnimationButton = game.Players.LocalPlayer.PlayerGui:WaitForChild("Annimations").HandsUp

PlayAnimationButton.MouseButton1Click:Connect(function()
	LoadAnimation = Humanoid:LoadAnimation(HandsUpAnimation)
	LoadAnimation:Play()
end)

PlayAnimationButton.MouseButton1Click:Connect(function()
	LoadAnimation:Stop()
end)

1st Goal: Trying to make this animation play when you press a button, and when you press it again it stop’s playing the animation.
2nd Goal: I made a hands up animation in Moon Animator, but when I play it the animation will show but then return to normal player position. How can I make it where it will show the hand’s when you press a button and it ill show that position forever until pressing the button again?

Some solutions I’ve tried was looking on websites and etc.

2 Likes

Humanoid:LoadAnimation() is dead use
Humanoid.Animator:LoadAnimation()

1 Like

Something like this?

PlayAnimationButton.MouseButton1Click:Connect(function()
	local LoadAnimation = Humanoid:LoadAnimation(HandsUpAnimation)
	LoadAnimation.Animator:Play()
end)
1 Like

you also got the player’s humanoid wrong

local player = game.Players.LocalPlayer
local Humanoid = player.Charcter:WaitForChild("Humanoid")
1 Like

that’s not was kidsteve923 said

1 Like

nope

PlayAnimationButton.MouseButton1Click:Connect(function()
	local LoadAnimation = Humanoid.Animator:LoadAnimation(HandsUpAnimation)
	LoadAnimation:Play()
end)
1 Like

Oop’s my bad. Didn’t realized you meant to put it in the variable.

1 Like

I had a error in my script.

Players.DeveloperCoolBoi.PlayerGui.Annimations.LocalScript:13: attempt to index nil with 'Stop'
1 Like
local HandsUpAnimation = game.Workspace.HandsUp
local Humanoid = game.Players.LocalPlayer:WaitForChild("Humanoid")
local PlayAnimationButton = game.Players.LocalPlayer.PlayerGui:WaitForChild("Annimations").HandsUp
local LoadAnimation = Humanoid.Animator:LoadAnimation(HandsUpAnimation)

PlayAnimationButton.MouseButton1Click:Connect(function()
	LoadAnimation:Play()
end)

PlayAnimationButton.MouseButton1Click:Connect(function()
	LoadAnimation:Stop()
end)
2 Likes

this would only make the animation stop
you should check if it’s already playing or not

2 Likes

What do you mean by that? Since my first goal is basically when you press the button again you will go back to default character animation.

1 Like

oh yea I didnt saw his code properly.

local HandsUpAnimation = game.Workspace.HandsUp
local Humanoid = game.Players.LocalPlayer:WaitForChild("Humanoid")
local PlayAnimationButton = game.Players.LocalPlayer.PlayerGui:WaitForChild("Annimations").HandsUp
local LoadAnimation = Humanoid.Animator:LoadAnimation(HandsUpAnimation)

local Playing = false
PlayAnimationButton.MouseButton1Click:Connect(function()
	if not playing then
		LoadAnimation:Play()
	else
		LoadAnimation:Stop()
	end
	Playing = not Playing
end)
1 Like

doing

is like doing

PlayAnimationButton.MouseButton1Click:Connect(function()
	LoadAnimation:Play()
	LoadAnimation:Stop()
end)

only because they’re the same button

1 Like

The code didn’t work. It had red lines which mean’s a syntax error I think. Should I try this?

PlayAnimationButton.MouseButton1Click:Connect(function()
	LoadAnimation:Play()
	LoadAnimation:Stop()
end)
1 Like

‘red lines’ means you should attempt to make it work for your game instead of copy and pasting it and expecting it to work ``/

No you should not do

PlayAnimationButton.MouseButton1Click:Connect(function()
	LoadAnimation:Play()
	LoadAnimation:Stop()
end)

this will only make it stop your animation

Wait nope it doesn’t work. It would just stop it right after.

local HandsUpAnimation = game.Workspace.HandsUp
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local PlayAnimationButton = game.Players.LocalPlayer.PlayerGui:WaitForChild("Annimations").HandsUp
local LoadAnimation = Humanoid.Animator:LoadAnimation(HandsUpAnimation)


local Playing = false
PlayAnimationButton.MouseButton1Click:Connect(function()
	if not Playing then
		LoadAnimation:Play()
	else
		LoadAnimation:Stop()
	end
	Playing = not Playing
end)

Fixed the error, now let me test it out

image
is it called ‘Annimations’ ?

Oop, I named the Gui innocently

Yay, the script works. Also how could I achieve my second goal?