Playing Animation on Mouse Click

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    My goal is, when you press a button an animation will play.
  2. What is the issue? Include screenshots / videos if possible!
    Basically when I press the button it won’t play the animation.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Looking on YouTube etc.
local HandsUpAnimation = game.Workspace.HandsUp

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild(“Humanoid”)

local PlayAnimationButton = game.Players.LocalPlayer.PlayerGui:WaitForChild(“ScreenGui”).TextButton

local LoadAnimation = Humanoid:LoadAnimation(HandsUpAnimation)

PlayAnimationButton.MouseButton1Click:Connect(function()

LoadAnimation:Play()

end)

First question. Are you receiving any errors in the output?

Second question. Are you using a server script?

Try using RemoteEvents to make it so when you click on the client, it plays the animation on the server. Idk if it would work

No errors in the output and I using a local script. QUESTION: On another script I was making I made a LOCAL script where when you press a key it will make the player’s speed reduce. Will other people be able to see it???

yes, other people would be able to see it, speed could be changed via server and via client

is this a local script or a script?
make sure its a localscript also can’t you just put it inside the “gui button”? so you could easily do

script.Parent.MouseButton1Click:Connect(function()

end)

My animation is in a local script

where is the localscript located?

So how could I make the animation play when you press that button?

In server script service. Would that change anything?

yes, localscripts cannot run in serverscriptservice. put it in StarterGui

Huh… where in StarterGui. Since that’s a folder for gui’s

putting this inside the button itself would work.

local HandsUpAnimation = game.Workspace.HandsUp

local PlayAnimationButton = script.Parent

local Player = game.Players.LocalPlayer

PlayAnimationButton.MouseButton1Click:Connect(function()
local Anim = Player.Character.Humanoid:LoadAnimation(HandsUpAnimation)
Anim:Play()
end)
local HandsUpAnimation = game.Workspace.HandsUp
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local PlayAnimationButton = script.Parent
local LoadAnimation = Humanoid:LoadAnimation(HandsUpAnimation)

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

Like this?

no don’t put the Humanoid outside the mousebutton event. do like what i did.

Like this?

local HandsUpAnimation = game.Workspace.HandsUp
local PlayAnimationButton = script.Parent

PlayAnimationButton.MouseButton1Click:Connect(function()
	local LoadAnimation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(HandsUpAnimation)
	LoadAnimation:Play()
end)

yes you can try that. char limit

Char limit??? What does that mean

Ok. Also I know this kind of off topic BUT how can I make this animation not go back to the ROBLOX’s default position when it’s done playing. Like how can I make it never stop and it make the character’s hand in the same position until I press a button?

Since right now when I move it also move’s the hand too which I don’t want. Plus I also don’t want it going back to the default ROBLOX position.