Advertisement
ToxicTheBoss

Untitled

Feb 7th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. --[[
  2.     This module links the topbar's chat button click to opening the UI.
  3. ]]
  4.  
  5. return function(window)
  6.     --------------- Variables: ---------------
  7.  
  8.     local connectionsList = {}
  9.     local tries = 0;
  10.     local maxAttempts = 35;
  11.    
  12.     --------------- Functions: ---------------
  13.  
  14.     local function addObjects(bindableClass,targetName,...)
  15.         local target = connectionsList[targetName];
  16.         if(not target) then
  17.             target = {};
  18.             connectionsList[targetName] = target;
  19.         end
  20.         local names = {...};
  21.         for _,name in pairs(names) do
  22.             local signal = Instance.new(bindableClass);
  23.             signal.Name = targetName.."_"..name;
  24.             target[name] = signal;
  25.         end
  26.     end
  27.    
  28.     --------------- Setup events: ---------------
  29.  
  30.     addObjects(
  31.         "BindableEvent","ChatWindow","ToggleVisibility","SetVisible","FocusChatBar","TopbarEnabledChanged","SpecialKeyPressed",
  32.         "CoreGuiEnabled","ChatBarFocusChanged","VisibilityStateChanged", "MessagesChanged","MessagePosted"
  33.     )
  34.    
  35.     --------------- Connect events: ---------------
  36.  
  37.     while(tries < maxAttempts) do
  38.         local success,result = pcall(function()
  39.             game:GetService("StarterGui"):SetCore("CoreGuiChatConnections",connectionsList);
  40.         end)
  41.         if(success) then
  42.             break;
  43.         else
  44.             tries += 1;
  45.             if(tries == maxAttempts) then
  46.                 error("Error calling SetCore CoreGuiChatConnections:",result);
  47.             else
  48.                 wait();
  49.             end
  50.         end
  51.     end
  52.    
  53.     --------------- Link chat button clicked: ---------------
  54.    
  55.     shared.connectionsList = connectionsList.ChatWindow;
  56.        
  57.     local callback = function(enabled)
  58.         if(enabled) then
  59.             window.Visible = true;
  60.         else
  61.             window.Visible = false;
  62.         end
  63.     end
  64.  
  65.     local enabled = true;
  66.     local toggle = function()
  67.         connectionsList.ChatWindow.VisibilityStateChanged:Fire(not enabled);
  68.         enabled = not enabled;
  69.         callback(enabled);
  70.     end
  71.  
  72.     for i = 1,2 do
  73.         toggle();
  74.     end
  75.  
  76.     connectionsList.ChatWindow.ToggleVisibility.Event:Connect(toggle);
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement