Cool Modules Script Roblox GUI

You may be currently working with module scripts with GUIs for the first time, Unfortunately, you do not understand how to put a GUI in a Module script or put the module script in the gui. In other words, you do not even know the ModuleScript to work with GUI.

Thankfully, this post will show you the ModuleScript that you can use to work with GUI. One thing you should know here is that ModuleScript cannot be replicated by moving the GUI. You definitely need to require it with the script itself.

Cool Modules Script Roblox GUI

So, if you want to know the ModuleScript to work with GUI, let’s see our post below!

ModuleScript with GUI

Here’s the Module Script:

local module = {}

local findframe = script.Parent.Parent.Gui — Finding the Gui

local closeframe = script.Parent — Getting all of the frames in my gui

local Current = script.Parent.CurrentGui.Value — Ignore I couldn’t get this to work properly

function module:Open(frame) — function for opening the targetted gui

script.Sounds.Click:Play()

            local frame = findframe:FindFirstChild(frame):TweenPosition(UDim2.new(0.5,0,0.5,0), “In”,”Bounce”,1) — tween the gui

Current = tostring(frame)  — frame is the name of the frame I want to open

end

function module:Close(frame) — Pretty self explanatory

script.Sounds.Click:Play()

closeframe:FindFirstChild(frame):TweenPosition(UDim2.new(0.5,0,1.5,0), “Out”,”Bounce”,1)

end

Here’s for Return Module:

local module = require(script.Parent:WaitForChild(‘GuiModule’))

local player = game.Players.LocalPlayer

local gui = script.Parent.Parent.Gui

local test = “test” — I’d have to do variables for every gui in my game

— Open And Closing GUI’s

gui.Open.MouseButton1Click:Connect(function()

module:Open(test) — Opens a gui with the name “test”

end)

gui.test.Close.MouseButton1Click:Connect(function()

module:Close(test) — Closes the gui

end)

Okay, that’s the ModuleScript that you can use when working with GUI. Now, it’s your turn to try working with ModuleScript and GUI.

How Does ModuleScript Work in Roblox?

The best way that allows you to copy the codes into multiple scripts is by utilizing the ‘ModuleScript’. In other words, ModuleScript is a unique type of script which will return a single value, commonly a table or function which is useful to multiple scripts.

However, ModuleScript does not run the code by itself, but it will need the ‘Require’ function. This function  will accept the Module Script as its only argument.  Well, the location of the module script is in the Explorer.

ModuleScript is a type of Lua source container which can run once and should return exactly one value. However, this value will be then returned by a call to ‘require’ given the ModuleScript as the only argument.

ModuleScripts are important objects  for following the ‘don’t-repeat-yourself (DRY) principle. Then, if you write a function, you can write it only once and use it everywhere.

How to Get Return Values in ModuleScript?

You need to know that the return values from ModuleScripts are independent regarding LocalScripts and Scripts and also other environments like the Command Bar. You can also use ‘require’ on a ModuleScript in a LocalScript to run the code on the client, even if a Script is already on the server.

using ‘require’ on a ModuleScript in the hierarchy with the Command bar, it will give a similar behavior. So, you need to be careful if you’re using a ModuleScript on the client and server at the same time, or debugging it within Studio.

‘Require’ in ModuleScript will run once. It will then return a single value. To return the exact same table, you can call ‘require’ again in the script. Need to know, the module itself will never run multiple times.

In other words, it will only apply when ‘require’ is called from either a server-side Script or client-side LocalScript. If you ‘require’ the module from both sides, a unique table will be then returned for each side.

How to Write ModuleScripts?

ModuleScripts are usually placed in ServerScriptService when it’s used by server-side Scripts and RelicatedStorage when used by client-side LocalScripts. In this case, ModuleScripts can be used when parented to any object as long as another script has access to it as well.

Well, a ModuleScript will start out with this code, when create:

    1. local module = {}
    2.  
    3. return module

The line local module = {} will create an empty table to store the module’s contents. However, this table will be then returned (return module), so that it’s given to other scripts which access the module.

You must also rename this table and then modify the return line, according to the module’s purposes, such as PickupManager. This is also a good idea to rename the ModuleScript itself to match.

    1. local PickupManager = {}
    2.  
    3. return PickupManager

How to Utilize the Calling Module?

Module should return something, that’s the return value of the required function. In this case, all codes are run in the module when called and the return type is returned. It’s commonly a table of properties, functions and events or also a function which does something to the game.

Somehow, the return type will be anything, including nil. Once the module is loaded, you definitely can call any of its functions with a similar dot notation format.

Learn About GUI

GUI stands for Graphical User Interface. GUI is basically an interface which is composed of multiple elements, some of which you can even interact with. GUIs also contain HUDs but also buttons, menus, sliders, settings and more.

GUI can be mentioned as one of exploits in Roblox where it allows the players too much freedom, working with scripts. It means that when you want to work with GUI, you should find the script before.

Unfortunately, GUI scripts are hard to find. In fact, not all UTG scripts are working, most of them are not valid to use. In this case, we should know that not all players which are using UTG in their games are absolutely inclined to share the script.

Well, the alternative way to obtain the GUI scripts is from V3rmillion forums. However, it may take you a while to find out what you are looking for. What you should do is to spend your time on this forum, be patient that you may be one of the lucky ones in this forum to eventually find the scripts.

Leave a Reply

Your email address will not be published. Required fields are marked *