Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is local and module script?

Asked by 8 years ago

Hello everyone,

I just started to learn scripting so that I can make a game. As i was learning some lua code, I realized that there are three different types of script. Module Script, Local Script and Script. I understand that script is used to give commands to objects but what is local script and module script?

Thanks

2 answers

Log in to vote
6
Answered by 8 years ago
Edited 6 years ago

Welcome to the realm of coding, we hope you stick around for a while.

Overview

This is actually a very decent question to start off with, because the concept is so simple, yet so important to understand. Before I go into excruciating detail about each one of these scripts and their significant purpose, you should probably know the fundamentals of networking (i'll try not to over complicate this).

The Client-Server Architecture

In the age of computers, we work under a model called the client-server architecture. This model is based on the concept of having a server to centralize information, and clients (your personal computer) to receive and use that information.

"So, what exactly is the difference between a server and a client?"

Well, it's important to know that a server isn't just an invisible entity. A server is actually a physical machine that's managing this information somewhere, just like your personal computer is managing information right now (but in a much different way). The server's main (or only) priority is storing, processing, and sending information received by an external source. Think of the server as a mail man, or your local post office.

Why is this Important?

This is important because the type of script you use determines what machine will run it's source code. Let me explain...

Server Scripts

A server script is the "Script" you're referring to. Most people just call it a "normal script," though I don't really like this term since server scripts have a specific purpose. The code inside a server script will be executed on ROBLOX's computers, and send over your network connection to your computer. This is called replication.

Local Scripts

A local script is what you may or may not have guessed at this point -- a script that executes code locally (meaning the machine it's running on). This type of script, or execution process, is done client-sided. Anything "client-sided" is being preformed by the individual computer.

Since a local script runs code on the client, it's is extremely important to know that this is vital for dealing with any form of user input (i.e, when you press a key, or when you click your mouse). In fact, in every client-server model, it's the client that does all the work. The only thing the server is doing is taking information, processing it, then sending it off to the devices connected to the network.

Module Scripts

A module script can be both client-sided, OR server-sided. You could just look at a module script as a block of code that can be used to cut your program up into manageable sections. You can retrieve the source code from a module script via the require function, which will execute the code inside the module script, and return whatever the module returns to whatever required it.

"But what side of the network does the code inside a module run on?"

Module scripts actually run their code on the machine of whatever required it. For example, if a local script required a module, the code inside the module will run client-sided. But if a server script requires the module, the code inside of it will run on the server.

More about modules?

The way modules work, very similarly resembles how functions work. The module executes its code, and returns a result. Only difference is, a return result is needed in a module script, and is only limited to one. I could go on about this, but I've given a more in depth answer about how they work here.

Other sources

Hope this explanation helped. If you have any questions, just let me know!

0
A+ BlackJPI 2658 — 8y
Ad
Log in to vote
0
Answered by
LostPast 253 Moderation Voter
8 years ago

A local script is a script that can only be used in the client side(Player's computer); StarterGui, StarterPack,StarterPlayer,Character. local scripts can be used for special code such as, local plr = game.Players.LocalPlayer which gets the plr. http://wiki.roblox.com/index.php?title=API:Class/LocalScript

A module script is a script that houses a library of functions. You can think of it like a table of functions that can be called from another script. http://wiki.roblox.com/index.php?title=API:Class/ModuleScript

Answer this question