HowToRoblox

ChatClient

Oct 18th, 2020
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
  2.  
  3.  
  4. local chatInput = script.Parent:WaitForChild("ChatInput")
  5.  
  6.  
  7. local uis = game:GetService("UserInputService")
  8.  
  9.  
  10. local onChatInputted = game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("ChatEvent")
  11.  
  12.  
  13. local cooldown = 1
  14.  
  15. local isCoolingDown = false
  16. local isChatting = false
  17.  
  18.  
  19. local msgsContainer = game.ReplicatedStorage:WaitForChild("Containers"):WaitForChild("ChatMessageContainer")
  20. local messageFrame = script.Parent:WaitForChild("ChatMessageFrame")
  21.  
  22.  
  23. local defaultSize
  24.  
  25. game:GetService("RunService").RenderStepped:Connect(function()
  26.  
  27.     messageFrame:ClearAllChildren()
  28.     Instance.new("UIListLayout", messageFrame)
  29.  
  30.     for i, messageValue in pairs(msgsContainer:GetChildren()) do
  31.        
  32.         messageValue = messageValue:Clone()
  33.        
  34.         if messageValue:IsA("TextLabel") then
  35.            
  36.             messageValue.Size = defaultSize or UDim2.new(1, 0, messageFrame.Size.Y.Scale/5, 0)
  37.  
  38.             messageValue.Parent = messageFrame
  39.  
  40.  
  41.             messageFrame.CanvasSize = UDim2.new(0, 0, #msgsContainer:GetChildren()/10, 0)
  42.            
  43.             if i == 1 then defaultSize = UDim2.new(0, messageValue.AbsoluteSize.X, 0, messageValue.AbsoluteSize.Y) end
  44.  
  45.         end
  46.     end
  47. end)
  48.  
  49.  
  50. uis.InputBegan:Connect(function(key, gameProcessed)
  51.  
  52.     if key.KeyCode == Enum.KeyCode.Slash and not gameProcessed then
  53.        
  54.         isChatting = true
  55.        
  56.         wait()
  57.         chatInput:CaptureFocus()       
  58.     end
  59. end)
  60.  
  61.  
  62. chatInput.FocusLost:Connect(function(enterPressed)
  63.  
  64.     if not enterPressed then return end
  65.    
  66.     isChatting = false
  67.  
  68.  
  69.     local input = chatInput.Text
  70.  
  71.     chatInput.Text = ""
  72.  
  73.  
  74.     if string.len(input) > 0 then
  75.  
  76.  
  77.         if isCoolingDown == true then
  78.  
  79.             chatInput.Text = "Wait for cooldown to end!"
  80.            
  81.             wait(1)
  82.            
  83.             if not isChatting then chatInput.Text = "" end
  84.  
  85.             return     
  86.         end
  87.  
  88.         isCoolingDown = true
  89.  
  90.  
  91.         onChatInputted:FireServer(input)
  92.  
  93.  
  94.         wait(cooldown)
  95.  
  96.         isCoolingDown = false  
  97.     end
  98. end)
Add Comment
Please, Sign In to add comment