lexishh
(lexishh)
June 27, 2020, 1:30pm
#1
I recently made a Donator perks UI and I have always been fascinated on how admin scripts and other models have such minimum code, until I found out about modules, I am clueless with them except it stops you from repeating your code, but how would I load a module into a game using require()
? I want to use this to load in a Donator perks that you setup with a gamepassid in the loader script.
You can download current donator perks for reference: https://www.roblox.com/library/5233746733/DonateUI
modules basically let you import a bunch of objects into your code, usually they are functions. In a module script, you write a bunch of code and then at the end you “return” something. The vast majority of the time, it’ll be a table which contains multiple functions (so what you are doing in the module script is writing functions for the table.)
Here is an example
--Module script named "ModuleScript" in ServerScriptService
local tableToReturn = {}
function tableToReturn.GetNumberOfPlayers()
print(#game.Players:GetChildren())
end
return tableToReturn
---------------------------
--Server or local script:
local module = require(game.ServerScriptService.ModuleScript)
module.GetNumberOfPlayers()
--Will print the # of players
1 Like
LocalWE
(WillPlayer)
June 27, 2020, 1:40pm
#3
I use modules to fire a bunch of remote events at specific times. I have another script that says to run the module script at a specific time. This is what happens in the live event that I made for July 4 10 AM MDT
local module = {}
module.Main = function()
game.ReplicatedStorage.LiveEvent.HideCountdown:FireAllClients()
game.Workspace.LiveEventMusic.Playing = true
game.ReplicatedStorage.LiveEvent.ShowUI1:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI1:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI2:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI2:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI3:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI3:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI4:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI4:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI5:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI5:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI6:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI6:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI7:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.ShowUI8:FireAllClients()
game.ReplicatedStorage.LiveEvent.HideUI7:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI8:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI9:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI9:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI10:FireAllClients()
wait(0.5)
game.ReplicatedStorage.LiveEvent.WhenUI.HideChangeJob:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideUser1:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideHealth:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideTopbar:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideRun:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideUser2:FireAllClients()
wait(5)
game.ReplicatedStorage.LiveEvent.HideUI10:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI11:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI11:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI12:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI12:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI13:FireAllClients()
wait(0.5)
game.Workspace.BankYeet:Destroy()
game.Workspace.LiveEventMusic.Playing = false
wait(5)
game.ReplicatedStorage.LiveEvent.HideUI13:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI14:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI14:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI15:FireAllClients()
wait(5)
game.ReplicatedStorage.LiveEvent.HideUI15:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI16:FireAllClients()
end
return module
1 Like
You can shorten this if it’s one function:
function Main()
game.ReplicatedStorage.LiveEvent.HideCountdown:FireAllClients()
game.Workspace.LiveEventMusic.Playing = true
game.ReplicatedStorage.LiveEvent.ShowUI1:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI1:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI2:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI2:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI3:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI3:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI4:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI4:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI5:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI5:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI6:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI6:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI7:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.ShowUI8:FireAllClients()
game.ReplicatedStorage.LiveEvent.HideUI7:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI8:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI9:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI9:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI10:FireAllClients()
wait(0.5)
game.ReplicatedStorage.LiveEvent.WhenUI.HideChangeJob:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideUser1:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideHealth:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideTopbar:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideRun:FireAllClients()
game.ReplicatedStorage.LiveEvent.WhenUI.HideUser2:FireAllClients()
wait(5)
game.ReplicatedStorage.LiveEvent.HideUI10:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI11:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI11:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI12:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI12:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI13:FireAllClients()
wait(0.5)
game.Workspace.BankYeet:Destroy()
game.Workspace.LiveEventMusic.Playing = false
wait(5)
game.ReplicatedStorage.LiveEvent.HideUI13:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI14:FireAllClients()
wait(10)
game.ReplicatedStorage.LiveEvent.HideUI14:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI15:FireAllClients()
wait(5)
game.ReplicatedStorage.LiveEvent.HideUI15:FireAllClients()
game.ReplicatedStorage.LiveEvent.ShowUI16:FireAllClients()
end
return Main
Module scripts basically will only return one of ANY value, so a function, table ,number etc
lexishh
(lexishh)
June 27, 2020, 1:42pm
#6
I understand modules in that sense, but how would I go about loading in a module with a UI from the library from a loader script inside the game?
This feature is deprecated, so you cannot import a library Module anymore, you will have to replicate it in the hierarchy
lexishh
(lexishh)
June 27, 2020, 1:45pm
#8
I thought you still could as long as it’s not private. Models like Basic admin use modules.
LocalWE
(WillPlayer)
June 27, 2020, 1:45pm
#9
In the UI You would do this: (Local Script)
game.ReplicatedStorage.LiveEvent.ShowUI1.OnClientEvent:Connect(function()
script.Parent.Frame.Visible = true
end)
game.ReplicatedStorage.LiveEvent.HideUI1.OnClientEvent:Connect(function()
script.Parent.Frame.Visible = false
end)
And have a remote event for the UI in that spot provided. (game.ReplicatedStorage.LiveEvent in my case)
1 Like
No, you cannot anymore, like I said: It’s deprecated
lexishh
(lexishh)
June 27, 2020, 1:50pm
#11
This is what I was trying to achieve in this topic, I’ll set this as a soloution.