Advertisement
HowToRoblox

EmotesClient

Oct 1st, 2022
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.96 KB | None | 0 0
  1. local repl = game.ReplicatedStorage:WaitForChild("EmotesReplicatedStorage")
  2. local re = repl:WaitForChild("RE")
  3. local allEmotes = repl:WaitForChild("Emotes")
  4.  
  5.  
  6. --Opening and closing the UI
  7. local sBtn = script.Parent:WaitForChild("ShopButton")
  8. local sFrame = script.Parent:WaitForChild("ShopFrame")
  9.  
  10. sBtn.MouseButton1Click:Connect(function()
  11.     sFrame.Visible = not sFrame.Visible
  12. end)
  13. sFrame.CloseButton.MouseButton1Click:Connect(function()
  14.     sFrame.Visible = false
  15. end)
  16.  
  17. local iBtn = script.Parent:WaitForChild("InventoryButton")
  18. local iFrame = script.Parent:WaitForChild("InventoryFrame")
  19.  
  20. iBtn.MouseButton1Click:Connect(function()
  21.     iFrame.Visible = not iFrame.Visible
  22. end)
  23. iFrame.CloseButton.MouseButton1Click:Connect(function()
  24.     iFrame.Visible = false
  25. end)
  26.  
  27. iFrame.Visible = false
  28. sFrame.Visible = false
  29. sFrame.SelectedEmoteFrame.Visible = false
  30.  
  31.  
  32. --Emotes inventory
  33. local emotesF = game.Players.LocalPlayer:WaitForChild("Emotes")
  34.  
  35. local playingEmotes = {}
  36.  
  37. function createInv()
  38.    
  39.     for i, child in pairs(iFrame.EmotesScroller:GetChildren()) do
  40.         if child:IsA("TextButton") then
  41.             child:Destroy()
  42.         end
  43.     end
  44.    
  45.     local btns = {}
  46.    
  47.     for i, emote in pairs(emotesF:GetChildren()) do
  48.        
  49.         local btn = script.PlayEmoteButton:Clone()
  50.         local emoteN = emote.Name
  51.         btn.Text = emoteN
  52.        
  53.         local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
  54.         local humanoid = char:WaitForChild("Humanoid")
  55.         local loadedAnim = humanoid:LoadAnimation(emote)
  56.         loadedAnim.Priority = Enum.AnimationPriority.Action
  57.        
  58.         btn.MouseButton1Click:Connect(function()   
  59.             if loadedAnim.IsPlaying then
  60.                 loadedAnim:Stop()
  61.             else
  62.                
  63.                 for i, playingEmote in pairs(playingEmotes) do
  64.                     playingEmote:Stop()
  65.                     table.remove(playingEmotes, i)
  66.                 end
  67.                 loadedAnim:Play()
  68.                 table.insert(playingEmotes, loadedAnim)
  69.             end
  70.         end)
  71.        
  72.         table.insert(btns, btn)
  73.     end
  74.    
  75.     table.sort(btns, function(a, b)
  76.         return a.Text < b.Text
  77.     end)
  78.    
  79.     for i, btn in pairs(btns) do
  80.         btn.Parent = iFrame.EmotesScroller
  81.     end
  82. end
  83.  
  84. createInv()
  85. emotesF.ChildAdded:Connect(createInv)
  86. emotesF.ChildRemoved:Connect(createInv)
  87.  
  88.  
  89. --Emotes shop
  90. local cash = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
  91.  
  92. function createShop()
  93.  
  94.     for i, child in pairs(sFrame.EmotesScroller:GetChildren()) do
  95.         if child:IsA("TextButton") then
  96.             child:Destroy()
  97.         end
  98.     end
  99.  
  100.     local btns = {}
  101.  
  102.     for i, emote in pairs(allEmotes:GetChildren()) do
  103.  
  104.         if emote:FindFirstChild("PRICE") then
  105.             local btn = script.SelectEmoteButton:Clone()
  106.             local emoteN = emote.Name
  107.             btn.EmoteName.Text = emoteN
  108.                
  109.                
  110.             local cam = Instance.new("Camera")
  111.             cam.Parent = btn.EmotePreview
  112.             btn.EmotePreview.CurrentCamera = cam
  113.                
  114.             local char = repl.PreviewCharacter:Clone()
  115.             char.Parent = btn.EmotePreview
  116.            
  117.             local hrp = char.HumanoidRootPart
  118.             cam.CFrame = CFrame.new(hrp.Position + hrp.CFrame.LookVector * 5, hrp.Position)
  119.                
  120.  
  121.             local price = emote.PRICE.Value
  122.  
  123.             btn.MouseButton1Click:Connect(function()
  124.  
  125.                 sFrame.SelectedEmoteFrame.EmoteName.Text = emoteN
  126.  
  127.                 if not emotesF:FindFirstChild(emoteN) then
  128.                     sFrame.SelectedEmoteFrame.BuyButton.Text = "BUY for $" .. price
  129.                 else
  130.                     sFrame.SelectedEmoteFrame.BuyButton.Text = "OWNED"
  131.                 end
  132.                    
  133.                 sFrame.SelectedEmoteFrame.EmotePreview:ClearAllChildren()
  134.                    
  135.                 local cam2 = Instance.new("Camera")
  136.                 cam2.Parent = sFrame.SelectedEmoteFrame.EmotePreview
  137.                 sFrame.SelectedEmoteFrame.EmotePreview.CurrentCamera = cam2
  138.  
  139.                 local wModel2 = Instance.new("WorldModel")
  140.                 local char2 = repl.PreviewCharacter:Clone()
  141.                 char2.Parent = workspace
  142.  
  143.                 local loadedAnim2 = char2.Humanoid:LoadAnimation(emote)
  144.                 loadedAnim2.Looped = true
  145.                 loadedAnim2:Play()
  146.                    
  147.                 wModel2.Parent = sFrame.SelectedEmoteFrame.EmotePreview
  148.                 char2.Parent = wModel2
  149.  
  150.                 local hrp2 = char2.HumanoidRootPart
  151.                 cam2.CFrame = CFrame.new(hrp2.Position + hrp2.CFrame.LookVector * 5.2, hrp2.Position)
  152.                    
  153.                 sFrame.SelectedEmoteFrame.Visible = true
  154.             end)
  155.  
  156.             table.insert(btns, btn)
  157.         end
  158.     end
  159.  
  160.     table.sort(btns, function(a, b)
  161.         local aPrice = allEmotes[a.EmoteName.Text].PRICE.Value
  162.         local bPrice = allEmotes[b.EmoteName.Text].PRICE.Value
  163.         return aPrice < bPrice or aPrice == bPrice and a.EmoteName.Text < b.EmoteName.Text
  164.     end)
  165.  
  166.     for i, btn in pairs(btns) do
  167.         btn.Parent = sFrame.EmotesScroller
  168.     end
  169. end
  170.  
  171. createShop()
  172. allEmotes.ChildAdded:Connect(createShop)
  173. allEmotes.ChildRemoved:Connect(createShop)
  174.  
  175.  
  176. --Send message to server to buy selected emote
  177. sFrame.SelectedEmoteFrame.BuyButton.MouseButton1Click:Connect(function()
  178.    
  179.     if sFrame.SelectedEmoteFrame.BuyButton.Text ~= "OWNED" then
  180.        
  181.         local emoteN = sFrame.SelectedEmoteFrame.EmoteName.Text
  182.         local emotePrice = allEmotes[emoteN].PRICE.Value
  183.        
  184.         if cash.Value >= emotePrice then
  185.             re:FireServer(emoteN)
  186.            
  187.             sFrame.SelectedEmoteFrame.BuyButton.Text = "OWNED"
  188.         end
  189.     end
  190. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement