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
01 | --//Animations |
02 | local facepalm = Instance.new( "Animation" ) |
03 | facepalm .AnimationId = "http://www.roblox.com/Asset?ID=3291600803" |
04 | local animTrack = p.Character.Humanoid:LoadAnimation(facepalm) |
05 |
06 | script.Parent.MouseButton 1 Click:Connect( function () |
07 | print ( "Facepalm played" ) |
08 | animTrack:Play() |
09 |
10 | end )` |
Thanks for helping
I don't know why it is not working, but did you put this in a LOCALSCRIPT? Also, change this:
1 | local player = game.Players.LocalPlayer |
2 | local facepalm = Instance.new( "Animation" ) |
3 | facepalm.AnimationId = "3291600803" |
4 | local animTrack = player.Character.Humanoid:LoadAnimation(facepalm) |
5 |
6 | script.Parent.MouseButton 1 Click:Connect( function () |
7 | animTrack:Play() |
8 | 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:
01 | local player = game.Players.LocalPlayer |
02 | local debounce = false |
03 | local facepalm = Instance.new( "Animation" ) |
04 | facepalm.AnimationId = "3291600803" |
05 | local animTrack = player.Character.Humanoid:LoadAnimation(facepalm) |
06 |
07 | script.Parent.MouseButton 1 Click:Connect( function () |
08 | if debounce = = false then -- if debounce is true, it's that the animation is playing |
09 | debounce = true |
10 | animTrack:Play() |
11 | wait( -- PUT HERE YOUR ANIMATION'S DURATION) |
12 | debounce = false |
13 | end |
14 | end ) |
Hope this helped!
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)
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | if debounce = = false then -- if debounce is true, it's that the animation is playing |
3 | debounce = true |
4 | script.Parent.Text = 'It works' |
5 | animTrack:Play() |
6 | wait( 4 ) |
7 | debounce = false |
8 | end |
9 | end ) |
`