Where to place an plugin's Guis, before placing it into CoreGui?

I want to know an place where i would place some guis, before i put them at the CoreGui, i have no idea on how to do this, because when using plugins, “script” seems to be an nil value, meaning i cannot place the guis inside the script.

And, i just learned something from this topic: https://devforum.roblox.com/t/plugins-making-an-interface/8314, don’t ask me why it is 5 years old.

When working with plugin UI there are two ways to go about it, either you create UI that is displayed in the world view or you create UI that is displayed inside of a widget (or maybe a combination of both!)

For CoreGUI

CoreGui is the container that Roblox uses for things such as the player leaderboard and chat, but in studio it can also be used for plugin UI that is displayed in the world view (the middle screen where you build). When making a plugin you will probably have a structure like this where you have a folder that represents the plugin and inside of it you have a Script that defines the plugin’s behavior alongside other objects you need for the plugin:

image
In the case of creating CoreGui plugin UI, you will want to put a ScreenGui inside of the folder. When you press on the plugin’s button you can use the script to clone this UI, put it in the CoreGui and then link all the button functionality. So in code it would look something like this:

local Gui = script.Parent.ScreenGui:Clone() -- assuming you have the ScreenGui directly inside the folder
Gui.Parent = game:GetService("CoreGui")
-- from here on you can index the Gui to program all buttons and functionality etc.
-- e.g. Gui.Button.MouseButton1Click:Connect(func)

For widgets

You can also use widgets, which I would recommend for modern plugins. Widgets were only added a couple years ago so before then you had to rely on the CoreGui. But widgets are a lot more convenient. This article should explain how widgets work, but the basic idea is similar to what I explained above. But instead of parenting the ScreenGui to the CoreGui, you will want to create a widget using plugin:CreateDockWidgetPluginGui(), which will then act as your ‘ScreenGui’ so to say. So you can parent frames, buttons and the like to the new widget and index it in a similar way. E.g. widget.Frame.Button.MouseButton1Click:Connect(func)

3 Likes

I have a question, if/when i set the position of the Guis in StarterGui, will they be in the same place they were set, when they are placed in the CoreGui?

Good question. When parenting to CoreGui your UI should indeed stay in the same place. If you go to the settings menu, there should be an option under the Studio tab to show the CoreGui in the explorer. You can then simply drag the ScreenGui into the CoreGui to verify if it’s in the right place while working on your plugin UI.

1 Like

Another question:

Should i make the MouseButton1Click events in the main script, or in scripts that i could put in the Guis? And if i need to do the second option, what type of script will it be? (Localscript/ServerScript)

I am actually not sure on using multiple scripts. I think scripts stand on their own run as soon as they are loaded so using multiple of them should be fine, but don’t quote me on that. As for the type of script, I always stick to regular scripts because plugins have no sense of ‘clients’ and ‘the server’, so I just use regular scripts.

You could also always use ModuleScripts to split your logic into smaller pieces if the main script gets very long.

2 Likes