HowToRoblox

MessageHandler

Jun 11th, 2021
642
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local re = game.ReplicatedStorage:WaitForChild("MessageSentRE")
  2.  
  3. local messagesFolder = Instance.new("Folder", game.ReplicatedStorage)
  4. messagesFolder.Name = "MessageFolder"
  5.  
  6.  
  7. local cooldown = 2
  8. local onCooldown = {}
  9.  
  10. local charLimit = 200
  11.  
  12.  
  13.  
  14. re.OnServerEvent:Connect(function(plr, msg)
  15.    
  16.    
  17.     if #msg > charLimit or #string.gsub(msg, " ", "") == 0 then return end
  18.    
  19.     if onCooldown[plr] then return end
  20.    
  21.     onCooldown[plr] = true
  22.    
  23.    
  24.     local filtered
  25.    
  26.     pcall(function()
  27.        
  28.         filtered = game:GetService("TextService"):FilterStringAsync(msg, plr.UserId)
  29.        
  30.         filtered = filtered:GetNonChatStringForBroadcastAsync()
  31.     end)
  32.    
  33.    
  34.     if not filtered then return end
  35.    
  36.    
  37.     local fullMessage = "[" .. plr.Name .. "]: " .. filtered
  38.    
  39.    
  40.     local str = Instance.new("StringValue")
  41.     str.Value = fullMessage
  42.     str.Parent = messagesFolder
  43.    
  44.    
  45.     game:GetService("Debris"):AddItem(str, 10)
  46.    
  47.    
  48.     wait(cooldown)
  49.     onCooldown[plr] = nil
  50. end)
RAW Paste Data