Advertisement
HowToRoblox

AnimationGuiHandler

Mar 22nd, 2021
11,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local anims = script:WaitForChild("Animations"):GetChildren()
  2.  
  3. local templateBtn = script:WaitForChild("AnimButton")
  4.  
  5.  
  6. local plr = game.Players.LocalPlayer
  7. local char = plr.Character or plr.CharacterAdded:Wait()
  8. local humanoid = char:WaitForChild("Humanoid")
  9.  
  10.  
  11. local currentAnim = nil
  12.  
  13.  
  14. for i, anim in pairs(anims) do
  15.    
  16.    
  17.     local loadedAnim = humanoid:LoadAnimation(anim)
  18.     loadedAnim.Looped = true
  19.     loadedAnim.Priority = Enum.AnimationPriority.Action
  20.    
  21.    
  22.     local templateClone = templateBtn:Clone()
  23.     templateClone.Text = anim.Name
  24.    
  25.     templateClone.Parent = script.Parent.AnimationsScroll
  26.    
  27.    
  28.     templateClone.MouseButton1Click:Connect(function()
  29.        
  30.         if currentAnim ~= loadedAnim then
  31.            
  32.             if currentAnim then currentAnim:Stop() end
  33.            
  34.             currentAnim = loadedAnim
  35.             currentAnim:Play()
  36.            
  37.            
  38.         elseif currentAnim == loadedAnim then
  39.            
  40.             currentAnim:Stop()
  41.             currentAnim = nil
  42.         end
  43.     end)
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement