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

What is the difference between Module, Local, and Server scripts?

Asked by 5 years ago

I've always used a server script with a ton of code to try to run a game but it never seems to work because it always gave me tons of bugs, errors, and was mostly messy. Just recently I have discovered Module scripts and was wondering what the differences in each script were so that I can have an understanding of what scripts each do. How are they useful for one another? The more information and the more resources I get would be useful. Here is a roblox script forum I was looking at:

Scripting with Module Scripts OR one big script

Thanks!

0
I personally discovered module scripts quite recently aswell and so far I've been using them to define 'classes' as you would in java or any other oop language. From what I've read module scripts are key if you are trying to implement oop in roblox, which is what I'm trying to accomplish. Leaving this as a comment as I'm not really answering your question, just pointing out a use to module scripts Le_Teapots 913 — 5y

1 answer

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago
Edited 5 years ago

ModuleScripts adopt the script type (and the abilities, but not the function environment) of the script that is requiring it.

For example:

in a localscript:

local LocalPlayer = require(workspace.ModuleScript) --> module returns function() return game.Players.LocalPlayer end;

print(LocalPlayer.Name) -->prints your name

In a serverscript:

local LocalPlayer = require(workspace.ModuleScript) --> module returns function() return game.Players.LocalPlayer end;

print(LocalPlayer.Name) --errors because server is not a player

LocalScripts are scripts that are ran on the client. They have the ability to reference events like RenderStepped (fires depending on the frame count) and the LocalPlayer. They also have the ability to create objects locally--but not shown on the server.

ServerScipts are scripts that can run instructions as if they were especially ordered from the server, allowing for two-side replication. You should do everything that needs to be replicated on the server. They do not have as many abilities as LocalScripts but they are definitely necessary for a completely functioning game.

postscript: please use the search function before you ask a question! ;)
Ad

Answer this question