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

Start to play animation by clicking textbutton?

Hey everyone, im trying to make a game like danceoff but the animations wont play when the buttons are clicked. Can somebody help me? This is how far i've come until now, but it doesnt work.

`local p = game.Players.LocalPlayer

--//Animations
local facepalm = Instance.new("Animation")
facepalm .AnimationId = "http://www.roblox.com/Asset?ID=3291600803"
local animTrack = p.Character.Humanoid:LoadAnimation(facepalm)
 
script.Parent.MouseButton1Click:Connect(function()
print("Facepalm played")
animTrack:Play()
 
end)`

Thanks for helping

1 comment

0

Do you own the animation? If not then studio won't let you play it.

2 answers

I don't know why it is not working, but did you put this in a LOCALSCRIPT? Also, change this:

local player = game.Players.LocalPlayer
local facepalm = Instance.new("Animation")
facepalm.AnimationId = "3291600803"
local animTrack = player.Character.Humanoid:LoadAnimation(facepalm)

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

I just changed the animation ID. We don't need what that is before it. Also, localscripts cannot print things, so I deleted that printing line. If it doesn't work, is the localscript "Disabled" in its properties?

Also, I suggest you to add a debounce:

local player = game.Players.LocalPlayer
local debounce = false
local facepalm = Instance.new("Animation")
facepalm.AnimationId = "3291600803"
local animTrack = player.Character.Humanoid:LoadAnimation(facepalm)

script.Parent.MouseButton1Click:Connect(function()
	if debounce == false then -- if debounce is true, it's that the animation is playing
		debounce = true
		animTrack:Play()
		wait(-- PUT HERE YOUR ANIMATION'S DURATION)
		debounce = false
	end
end)

Hope this helped!

1 comment

0

Thank you for answering, i did the following:

Well i tried what you said but now i get this: 19:20:08.004 - Invalid animation id '<error: unknown AssetId protocol>': the script: ` local player = game.Players.LocalPlayer local debounce = false local facepalm = Instance.new("Animation") facepalm.AnimationId = "3291600803" wait(3) local animTrack = player.Character.Humanoid:LoadAnimation(facepalm)

script.Parent.MouseButton1Click:Connect(function()
    if debounce == false then -- if debounce is true, it's that the animation is playing
        debounce = true
		script.Parent.Text = 'It works'
        animTrack:Play()
        wait(4)
        debounce = false
    end
end)

`

3 comments

0

Hi, I think what this output is saying is that your animation ID doesn't exists.

0

Try to recopy its animation id

0

yes i know how it works i had to try with another animation thx for th ehelp

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