Scripts vs Local Scripts

I’m a very new scripter, and I created a simple script that created a part and positioned it to the players torso when you pressed the key E, and I was so confused as to why it wasn’t working. So I created a local script and pasted it in there and it worked which confused me even more.

How am I supposed to know if a certain code I’m looking to make will require a Local Script vs a regular Script, or vice versa?

8 Likes

LocalScripts run on the users local machine, and is normally responsible for the actions of just the local player, while Server scripts run on the game Server.

In your case, your code only worked in a LocalScript because you can’t collect player input on the server. The Server can not tell when a user presses a certain key, or clicks the mouse.

ServerScripts are usually used for handling the main game controller, and things that you can not trust being run on a local machine.

Do keep in mind though, that since you did create the part locally, it will not appear for any of the other players in the game. FilteringEnabled prevents parts from replicating to the server, and to other clients.

15 Likes

Local script are used client-side actions like a stamina bar, scripts are used for server-side actions like a moving part.
Local scripts and Scripts cannot be placed whereever however, visit this link to learn more about this topic: Client-Server Runtime | Documentation - Roblox Creator Hub

This should explain all you need to know on placement.

4 Likes

Ohhh, okay I see.
But another question, can you combine things within Local Scripts and regular Scripts; Like local script related code into regular scripting code?
Or does the same rule apply?

1 Like

Acually yes for scripts, you can use playeradded(function() and characteradded(function().

However, for the most part you have to use remote functions/events so they can communicate and carrie out certain functions. Here’s a link: Custom Events and Callbacks | Documentation - Roblox Creator Hub

4 Likes

So I assume this would work if you were to connect a Local Script and Script together;

The Local Script consists of the player pressing a button and it connecting to the remote

The Script consists of the ending outcome of what would happen, like them shooting a fireball or something, and also connecting to the remote

2 Likes

Yah, however if you wat something to go to client to client, you need to use remote events and go client server client. Also! When it comes down to exploits try not to trust the client. You can use indicators to connect. Like a brick color to be red. so the exploiter can’t do much harm to the acual game.

2 Likes

Or you could become a great developer and write all your code locally!

In all seriousness though, the client/server boundary, when to use which for what, how and when to cross it, and how to secure both ends is a very complex and convoluted system for new developers, and even some aspects of it become challenging for advanced programmers.

It becomes easier with time as most things of this nature do, and no explanation I, nor anyone in this thread can give will create a full understanding of the use cases for each, to put it into basic terms though:

Local Scripts are for client-based interactions, text in a TextBox, a UserInput, the mouse’s position, etc.

Scripts (Server Scripts) control virtually everything else that your game does, how it functions and all that.

4 Likes