HowToRoblox

ChatInputScript

Mar 10th, 2020
1,564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. local chatInput = script.Parent:WaitForChild("ChatInput")
  2.  
  3.  
  4. local uis = game:GetService("UserInputService")
  5.  
  6.  
  7. local onChatInputted = game.ReplicatedStorage:WaitForChild("OnChatInputted")
  8.  
  9.  
  10. local cooldown = 1
  11.  
  12. local isCoolingDown = false
  13.  
  14.  
  15. uis.InputBegan:Connect(function(key, gameProcessed)
  16.        
  17.     if key.KeyCode == Enum.KeyCode.Slash and not gameProcessed then
  18.        
  19.         chatInput:CaptureFocus()       
  20.     end
  21. end)
  22.  
  23.  
  24. chatInput.FocusLost:Connect(function(enterPressed)
  25.  
  26.     if not enterPressed then return end
  27.    
  28.    
  29.     local input = chatInput.Text
  30.    
  31.     chatInput.Text = ""
  32.    
  33.    
  34.     if string.len(input) > 0 then
  35.        
  36.        
  37.         if isCoolingDown == true then
  38.            
  39.             chatInput.Text = "Wait for cooldown to end!"
  40.            
  41.             return     
  42.         end
  43.        
  44.         isCoolingDown = true
  45.        
  46.        
  47.         onChatInputted:FireServer(input)
  48.        
  49.        
  50.         wait(cooldown)
  51.            
  52.         isCoolingDown = false  
  53.     end
  54. end)
Add Comment
Please, Sign In to add comment