I am currenty building a RAGDOLL game. And this... | Roblox Forum
Welcome to the Forums!
Join thousands of other Roblox members with a free account.
Create Forum Account

I am currenty building a RAGDOLL game. And this...

  • This website was created by Roblox members to replace the official forums because Roblox shut them down! Join our community if you like to talk about Roblox!
Feb 20, 2020
95
12
8
Bundaberg
Roblox
Mark_Studios10
I don't know how to toggle the script to work. I put in the MODULE script in. And I don't even know how to toggle it.

Any videos, screenshots?
 
Feb 20, 2020
95
12
8
Bundaberg
Roblox
Mark_Studios10

Attachments

Last edited:

trains

Active Member
Jul 9, 2020
386
60
28
littleroot town, hoenn
Roblox
BhadTrains
Any videos, screenshots?
ModuleScript documentation is a place to start.
oh wait... i forgot about that lol
Post automatically merged:

Any videos, screenshots?
ModuleScript documentation is a place to start.
I looked in there... I still don't know how. View attachment 22888
View attachment 22889View attachment 22890View attachment 22891View attachment 22893View attachment 22894View attachment 22895View attachment 22896View attachment 22897

That's all it.
edge... words in the taskbar... this disturbs me... no offense
 

WizardOfHills

Active Member
Jul 21, 2018
579
113
43
Roblox
WizardOfHills
ModuleScript is a dormant (not active or dead) peace of code till someone calls require(...). The parameter to the require is the instance of the ModuleScript. Since its execution must be triggered, it does not matter where the script lives. There are no designated areas where ModuleScripts are executed by default (like ServerScriptService for Scripts or PlayerScripts for LocalScripts).

The ModuleScript must return one (and only one) value. It may be anything (except nil), but typically it is a table or function. Actually when you create a new ModuleScript it comes with a minimum script which returns an empty table. Typically you add items to this table and it may happen that you add a function or two to this table. Nice, you just created a small library of functions to be used in various scripts. It looks like this:

MyLib:
Code:
local module = {}

function module.HelloWorld(who)
    print("Hello World from " .. tostring(who))
end

return module
ScriptA and ScriptB have the same content:
Code:
mylib = require(script.Parent:WaitForChild("MyLib"))
mylib.HelloWorld(script)
The result is:
Code:
  Hello World from ScriptA
  Hello World from ScriptB
ModuleScripts.jpg

The returned value is passed as result of the require function. Moreover, this value is cached, so the script executes only once and all scripts which require the module have access to the same value. So if returned value is a table, than this same table is accessible (is shared) from all scripts which required the module. When one such script changes the table, the change is visible in all scripts. This allows for very efficient communication between scripts. At least much more efficient than creating IntValues or StringValues which are then replicated all over the game to all clients. TBC.
 
Feb 20, 2020
95
12
8
Bundaberg
Roblox
Mark_Studios10
Any videos, screenshots?
ModuleScript documentation is a place to start.
oh wait... i forgot about that lol
Post automatically merged:

Any videos, screenshots?
ModuleScript documentation is a place to start.
I looked in there... I still don't know how. View attachment 22888
View attachment 22889View attachment 22890View attachment 22891View attachment 22893View attachment 22894View attachment 22895View attachment 22896View attachment 22897

That's all it.
edge... words in the taskbar... this disturbs me... no offense
ModuleScript is a dormant (not active or dead) peace of code till someone calls require(...). The parameter to the require is the instance of the ModuleScript. Since its execution must be triggered, it does not matter where the script lives. There are no designated areas where ModuleScripts are executed by default (like ServerScriptService for Scripts or PlayerScripts for LocalScripts).

The ModuleScript must return one (and only one) value. It may be anything (except nil), but typically it is a table or function. Actually when you create a new ModuleScript it comes with a minimum script which returns an empty table. Typically you add items to this table and it may happen that you add a function or two to this table. Nice, you just created a small library of functions to be used in various scripts. It looks like this:

MyLib:
Code:
local module = {}

function module.HelloWorld(who)
    print("Hello World from " .. tostring(who))
end

return module
ScriptA and ScriptB have the same content:
Code:
mylib = require(script.Parent:WaitForChild("MyLib"))
mylib.HelloWorld(script)
The result is:
Code:
  Hello World from ScriptA
  Hello World from ScriptB
View attachment 22917

The returned value is passed as result of the require function. Moreover, this value is cached, so the script executes only once and all scripts which require the module have access to the same value. So if returned value is a table, than this same table is accessible (is shared) from all scripts which required the module. When one such script changes the table, the change is visible in all scripts. This allows for very efficient communication between scripts. At least much more efficient than creating IntValues or StringValues which are then replicated all over the game to all clients. TBC.
@trains I'm sorry if i have Microsoft Edge.
@WizardOfHills Thanks for the help!
 

WizardOfHills

Active Member
Jul 21, 2018
579
113
43
Roblox
WizardOfHills
I hope that HelloWorld example of ModuleScripts illustrates two points:
  1. ModuleScript is supposed to be required(...) from many scripts. Otherwise it could be just cut_and_pasted into the only script which requires it.
  2. Functions defined inside ModuleScript can be passed to outside as part of a table.
Let's have a look at a more useful example. We will put a label above items, so player can see where important points of interest are. It will look like this:

PartAB_1.jpg
PartAB_2.jpg
PartAB_3.jpg

MyLib:
Code:
local module = {}

function module.ShowName(part)
    local gui = Instance.new("BillboardGui")
    gui.Size = UDim2.new(20, 0, 5, 0)
    gui.StudsOffset = Vector3.new(0, part.Size.Y/2+2.5, 0)
    local txt = Instance.new("TextLabel", gui)
    txt.Size = UDim2.new(1, 0, 1, 0)
    txt.Position = UDim2.new(0, 0, 0, 0)
    txt.TextScaled = true
    txt.Text = part.Name
    gui.Parent = part
end

return module
ShowNameScript:
Code:
mylib = require(game.ServerStorage.MyLib)
mylib.ShowName(script.Parent)
Now suppose that we show the game to a friend and we get a feedback that grey rectangles look lame. So we decide to make labels transparent.

PartAB_4.jpg

Instead of changing code in three places we go and modify code only in one place.
Code:
local module = {}

function module.ShowName(part)
    local gui = Instance.new("BillboardGui")
    gui.Size = UDim2.new(20, 0, 5, 0)
    gui.StudsOffset = Vector3.new(0, part.Size.Y/2+2.5, 0)
    local txt = Instance.new("TextLabel", gui)
    txt.BackgroundTransparency = 1  -- added line
    txt.Size = UDim2.new(1, 0, 1, 0)
    txt.Position = UDim2.new(0, 0, 0, 0)
    txt.TextScaled = true
    txt.Text = part.Name
    gui.Parent = part
end

return module
 
General
Help Users
    F Fedruz53: huh