Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make a animation play when a gui is clicked?

Asked by 4 years ago

I also have 2 qestions one for the title and this: I have more then 1 animation do I just put the animation with the script in the gui?

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid

local animation = hum:LoadAnimation(script.Animation)
animation:Play()

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think the problem is that you used or in a variable. You should use a repeat until statement instead. Also, you will have to use the MouseButton1Click event and connect it to a function so the animation plays when you click it, make sure the script is a LocalScript, and make sure the gui instance is a TextButton.

local player = game:GetService("Players").LocalPlayer

repeat
    wait()
until player.Character

local char = player.Character
local hum = char:WaitForChild("Humanoid")

local animation = hum:LoadAnimation(script.Animation)

script.Parent.MouseButton1Click:Connect(function()
    animation:Play()
end)

And to answer your question, yes you should put the script with the animation inside the TextButton.

Ad

Answer this question