Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This module links the topbar's chat button click to opening the UI.
- ]]
- return function(window)
- --------------- Variables: ---------------
- local connectionsList = {}
- local tries = 0;
- local maxAttempts = 35;
- --------------- Functions: ---------------
- local function addObjects(bindableClass,targetName,...)
- local target = connectionsList[targetName];
- if(not target) then
- target = {};
- connectionsList[targetName] = target;
- end
- local names = {...};
- for _,name in pairs(names) do
- local signal = Instance.new(bindableClass);
- signal.Name = targetName.."_"..name;
- target[name] = signal;
- end
- end
- --------------- Setup events: ---------------
- addObjects(
- "BindableEvent","ChatWindow","ToggleVisibility","SetVisible","FocusChatBar","TopbarEnabledChanged","SpecialKeyPressed",
- "CoreGuiEnabled","ChatBarFocusChanged","VisibilityStateChanged", "MessagesChanged","MessagePosted"
- )
- --------------- Connect events: ---------------
- while(tries < maxAttempts) do
- local success,result = pcall(function()
- game:GetService("StarterGui"):SetCore("CoreGuiChatConnections",connectionsList);
- end)
- if(success) then
- break;
- else
- tries += 1;
- if(tries == maxAttempts) then
- error("Error calling SetCore CoreGuiChatConnections:",result);
- else
- wait();
- end
- end
- end
- --------------- Link chat button clicked: ---------------
- shared.connectionsList = connectionsList.ChatWindow;
- local callback = function(enabled)
- if(enabled) then
- window.Visible = true;
- else
- window.Visible = false;
- end
- end
- local enabled = true;
- local toggle = function()
- connectionsList.ChatWindow.VisibilityStateChanged:Fire(not enabled);
- enabled = not enabled;
- callback(enabled);
- end
- for i = 1,2 do
- toggle();
- end
- connectionsList.ChatWindow.ToggleVisibility.Event:Connect(toggle);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement