HowToRoblox

MessageDisplayer

Jun 11th, 2021 (edited)
742
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
  2.  
  3.  
  4. local re = game.ReplicatedStorage:WaitForChild("MessageSentRE")
  5.  
  6. local folder = game.ReplicatedStorage:WaitForChild("MessageFolder")
  7.  
  8.  
  9. local scroller = script.Parent.MessageScroller
  10.  
  11.  
  12. local ts = game:GetService("TweenService")
  13. local ti = TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
  14.  
  15.  
  16. local maxMsgs = 200
  17.  
  18. local messages = {}
  19.  
  20.  
  21.  
  22. folder.ChildAdded:Connect(function(child)
  23.    
  24.    
  25.     local textLabel = script.MessageTemplate:Clone()
  26.    
  27.     textLabel.Text = child.Value
  28.    
  29.     textLabel.TextTransparency = 1
  30.     textLabel.BackgroundTransparency = 1
  31.    
  32.     textLabel.Parent = scroller
  33.    
  34.     ts:Create(textLabel, ti, {TextTransparency = 0, BackgroundTransparency = 0}):Play()
  35.    
  36.    
  37.     table.insert(messages, {child.Value, textLabel})
  38.    
  39.    
  40.     if #messages > maxMsgs then
  41.        
  42.         messages[1][2]:Destroy()
  43.         table.remove(messages, 1)
  44.     end
  45.    
  46.     scroller.CanvasSize = UDim2.new(0, 0, 0, scroller.UIListLayout.AbsoluteContentSize.Y)
  47.    
  48.     scroller.CanvasPosition = Vector2.new(0, 9999)
  49. end)
  50.  
  51.  
  52. script.Parent.ChatInput.FocusLost:Connect(function(enterPressed)
  53.    
  54.     if not enterPressed then return end
  55.    
  56.     re:FireServer(script.Parent.ChatInput.Text)
  57.    
  58.     script.Parent.ChatInput.Text = ""
  59. end)
  60.  
  61.  
  62. game:GetService("UserInputService").InputBegan:Connect(function(inp, gameProcessed)
  63.    
  64.     if gameProcessed then return end
  65.    
  66.     if inp.KeyCode == Enum.KeyCode.Slash then
  67.        
  68.         wait()
  69.         script.Parent.ChatInput:CaptureFocus()
  70.     end
  71. end)
RAW Paste Data