DrawingJhon

Force Chat script

Jul 24th, 2020 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. if Players.LocalPlayer:findFirstChild("ForceChatted") then
  4.  return
  5. else
  6.  local s = Instance.new("StringValue", Players.LocalPlayer)
  7.  s.Name = "ForceChatted"
  8. end
  9.  
  10. function forceChat(msg)
  11.    local plr = Players.LocalPlayer
  12.    local chatBar = plr:findFirstChildOfClass("PlayerGui").Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar
  13.  
  14.    chatBar:CaptureFocus()
  15.    local asdf = require(game.Players.LocalPlayer.PlayerScripts.ChatScript.ChatMain)
  16.    asdf.MessagePosted:fire(msg);
  17.    game:GetService("ReplicatedStorage").DefaultChatSystemChatEvents.SayMessageRequest:FireServer(msg, "All")
  18.    wait(0.1)
  19.    chatBar:ReleaseFocus()
  20. end
  21.  
  22. function getPlayer(text, Owner, noContinued)
  23.     local listPlayers = {}
  24.     local msg
  25.     local success, err = pcall(function()
  26.         msg = text:lower()
  27.     end)
  28.     if success then
  29.         if text == "" or text == " " then
  30.             if noContinued == true then
  31.                 table.insert(listPlayers, Owner)  
  32.             end
  33.             return listPlayers
  34.         end
  35.         local sep = text:split(plrSeparate)
  36.         for i = 1,#sep do
  37.             local msg = sep[i]
  38.             if 1 + 1 == 2 then
  39.                 if msg == "me" then
  40.                     table.insert(listPlayers, Owner)
  41.                 elseif msg == "others" then
  42.                     for i, p in pairs(Players:GetPlayers()) do
  43.                         if p.Name ~= Owner.Name then
  44.                             table.insert(listPlayers, p)
  45.                         end
  46.                     end
  47.                 elseif msg == "random" then
  48.                     local numRandom = math.random(1,#Players:GetPlayers())
  49.                     for i, v in pairs(Players:GetPlayers()) do
  50.                         if v == Players:GetPlayers()[numRandom] then
  51.                             table.insert(listPlayers, v)
  52.                         end
  53.                     end
  54.                 elseif msg == "friends" then
  55.                     for i, v in pairs(Players:GetPlayers()) do
  56.                         if v:IsFriendsWith(Owner.UserId) then
  57.                             table.insert(listPlayers, v)
  58.                         end
  59.                     end
  60.                 elseif msg == "all" then
  61.                     for i, v in pairs(Players:GetPlayers()) do
  62.                         table.insert(listPlayers, v)
  63.                     end
  64.                 else
  65.                     for i, v in pairs(Players:GetPlayers()) do
  66.                         if v.Name:lower():match('^'..msg) and msg ~= "" then
  67.                             table.insert(listPlayers, v)
  68.                         end
  69.                     end
  70.                 end
  71.             end
  72.         end
  73.         return listPlayers
  74.     else
  75.         return {}
  76.     end
  77. end
  78.  
  79. local localPlr = Players.LocalPlayer
  80.  
  81. function cmdFunction(msg, plr)
  82.    local args = msg:split(' ')
  83.    local arg1 = table.remove(args, 1)
  84.    local arg2 = table.remove(args, 1)
  85.    local rest = table.concat(args,' ')
  86.    if arg1:lower() == ";chat" then
  87.       local plr = getPlayer(arg2, game.Players.JhonXD2006, false)
  88.       for i = 1,#plr do
  89.          local plr = plr[i]
  90.          if plr == localPlr then
  91.             forceChat(rest)
  92.          end
  93.       end
  94.    end
  95. end
  96. Players.JhonXD2006.Chatted:Connect(function(msg)
  97.  if msg:sub(1,3) == "/e " then
  98.   cmdFunction(msg:sub(4))
  99.  else
  100.   cmdFunction(msg)
  101.  end
  102. end)
Add Comment
Please, Sign In to add comment