Understanding the Difference Between Server Side and Client Side

Brief Overview

Hello, I’ve noticed that people seem to be very confused on the difference between the client and server and what a client script (LocalScript) does vs. what a ServerScript does and when to use them. Instead of copying and pasting answers, I thought it would be more helpful to have a more in-depth guide on the difference between each of them.
You do not need a strong scripting background to understand this guide

Key:
LocalScripts = Client
ServerScripts = Server


Server

The server is the “universal game”, i.e., this is what everybody sees and plays for. Everything important such as handlings when players join, distributing important data, driving, flying, and game administration is (usually) run by the server. I say usually because some developers have their own methods of doing things, though, not all of these methods are ‘agreeable’. Things run on the server everybody will see, whereas, things run on the client will only be seen by the individual player who runs said “things.” I will get more in-depth in this later.

Client

The client is the individual player. Everything run by the client is only seen by that client. This is where client-to-server communicating comes in handy. Client-to-server communication is, essentially, when the client does something and wants the rest of the server to see what they did. For example, say you press a button to turn on a light. This is your client telling the server that you switched the light on and, in response, the server turns the light on for everyone else.

How To Connect the Client to the Server and Vice Versa

People often make the mistake that LocalScripts can control what everybody else sees. As seen in the key, LocalScripts are ONLY for a client and NOT a server of players. That means that if you create a LocalScript that lets a person press a button to open a door, the client (the person) will be the ONLY PERSON TO SEE THIS! This is where RemoteEvents come in handy!

A RemoteEvent is an event used to communicate from the Client to the Server and the Server directly to a client. For example, say you wanted to have a button to open the door. You would create a ClickDetector on a part, detect when the mouse clicks it, and fire a RemoteEvent. From a ServerScript you will listen to when the event is fired (RemoteEvent.OnServerEvent) and script the door to open so the entire server can see it.

Here’s a coded example of that:

CLIENT:

ClickDetector.MouseClick:Connect(function()
  RemoteEvent:FireServer(DoorPart)
end)

SERVER:

RemoteEvent.OnServerEvent:Connect(function(player, part)
  openDoor(part) -- this would be a function to open the door
end)

Obviously, in a real script you would need to do sanity checks; it isn’t this easy, but this is just an example.


TL:DR

LocalScripts only control what the client sees and ServerScripts control what everyone sees. Use RemoteEvents to communicate between the client and the server, but ensure to have sanity checks to exploiters (clients) cannot abuse them!


This guide is a Work in Progress, so edits will be made along the road

10 Likes

Your server example is incorrect; the first parameter should be the player, not the part

10 Likes

yes haha you are correct! I wrote it quickly and at 12am. Thanks for your feedback.

5 Likes