Local Scripts (Server vs Client) - Roblox Advanced Scripting #1 (2023)

BrawlDev
19 Oct 202314:55

Summary

TLDRThis Roblox Advanced Scripting tutorial introduces the client-server model, crucial for game development. It explains how the server oversees game control and synchronization, while clients represent individual players. The video also demonstrates local scripts, which execute actions specific to a player without affecting others, using examples like changing a part's color on touch.

Takeaways

  • 👋 Welcome to the first episode of the Roblox Advanced Scripting Tutorial series.
  • 📺 It's recommended to watch the Beginner Scripting Tutorial Guide before this one.
  • 🛠️ This series will cover more advanced topics in Roblox scripting.
  • 🔍 The focus of this episode is on local scripts and the server-client model in Roblox.
  • 🌐 Every Roblox game uses a multiplayer model called the client-server model.
  • 🖥️ The server oversees the whole game and controls synchronization among players.
  • 👤 The client refers to each individual player connected to the server.
  • 🔁 Replication ensures all players see the same actions in the game.
  • 📡 Data can be transmitted between the server and clients in different ways.
  • 🔧 Local scripts are used to execute actions specific to one client without affecting others.
  • 🖥️ Example given: Inserting a local script in Roblox to print 'Hello World' for a single client.
  • 🎮 Example given: Changing part colors in the game for one client using a local script.
  • 🛠️ How to switch perspectives between the client and server in Roblox Studio.
  • 📋 Importance of understanding client-server models for developing Roblox games.
  • 👨‍💻 Practical examples and walkthroughs are provided for better understanding.

Q & A

  • What is the main focus of the first episode of the Roblox Advanced scripting tutorial?

    -The first episode focuses on explaining local scripts and the server-client model, which are essential for understanding how multiplayer games work in Roblox.

  • Why is it recommended to watch the beginner scripting tutorial before this advanced one?

    -It is recommended because the advanced tutorial covers more complicated topics, and having a foundational understanding from the beginner tutorial will help in grasping these advanced concepts more effectively.

  • What is the client-server model in the context of Roblox games?

    -The client-server model is a multiplayer model where the server oversees and controls the game, and the clients are individual players who interact with the game through their perspectives.

  • How does the server in a Roblox game function?

    -The server acts as an overseer, controlling everything that happens in the game and ensuring that all players see the same events, like character movements, happening on the server.

  • What is a client in the context of the server-client model in Roblox?

    -A client in this context refers to each individual player in the game. Each player's perspective and interactions with the game are managed as a client connected to the server.

  • What is replication in the context of the server-client model?

    -Replication is the process where events that occur on the server are copied and shown to every player in the game, ensuring that all players see the same thing happening in the game.

  • How does transmitting data between the server and clients work in Roblox?

    -Data can be transmitted from one client to the server, from the server to one client, or from the server to all clients. This is used to change game elements or to show specific information to certain players.

  • What is an example of a client-side feature in a Roblox game?

    -An example of a client-side feature is the user interface, like buttons and pop-ups, which may appear differently or only on specific players' screens, depending on their actions or progress in the game.

  • How can you switch between the client and server perspectives in Roblox Studio?

    -You can switch between perspectives by clicking on the 'current client' monitor in the test ribbon in Roblox Studio, which allows you to see the game from either the player's perspective or the server's perspective.

  • What is a local script in Roblox and why is it used?

    -A local script in Roblox is a script that runs only on the client side, not being replicated to the server. It is used for actions that should only happen within a specific player's game, like changing the color of an object when stepped on.

  • How can you create a local script in Roblox Studio?

    -You can create a local script by right-clicking on an object in the Explorer window, selecting 'Local Script', and then writing the script code in the script editor that appears.

Outlines

00:00

📚 Introduction to Roblox Advanced Scripting and Client-Server Model

The video script introduces the first episode of a Roblox Advanced Scripting tutorial series, emphasizing the importance of understanding the basics before delving into more complex topics. It suggests viewers watch a beginner's guide first and mentions the goal of becoming a top-tier Roblox developer. The script discusses the necessity of understanding the local scripts and the server-client model, which are fundamental to game development on Roblox. It explains the server as an overseer of the game, controlling all in-game actions and ensuring synchronization among players, while clients represent individual players with unique perspectives and interfaces. The tutorial also highlights replication and data transmission as key aspects of the server-client model.

05:02

🔄 Exploring the Server-Client Model with In-Game Examples

This section of the script delves deeper into the server-client model, using the game Pet Simulator X to illustrate how replication and client-side features work. It demonstrates how progress in the game can be unique to each player, with examples such as accessing different areas based on individual achievements. The script also explains how user interfaces can differ from one client to another, with buttons and panels being unique to each player's perspective. The importance of understanding this model for game development is reiterated, as it impacts how developers create experiences that are specific to individual players or replicated across all players.

10:04

🛠️ Accessing Client and Server Perspectives in Roblox Studio

The script provides a practical guide on how to switch between client and server perspectives within Roblox Studio. It explains that while playing a game in test mode, developers can use the test ribbon to toggle between the current client's view and the server's view. This feature is crucial for understanding and developing game mechanics that function differently on the client and server sides. The explanation includes the default camera locations for each perspective and how developers can move around freely in the server's view, akin to using Roblox Studio's 3D world.

💬 Creating and Understanding Local Scripts in Roblox

The final part of the script introduces local scripts in Roblox, which are used to execute actions only within a specific player's game environment without being replicated on the server. It guides viewers through creating a local script attached to a part in the game, demonstrating how to change the part's color when a player touches it. The script also explains how to troubleshoot errors related to object references and how to use 'wait for child' to ensure objects are loaded before the script runs. The tutorial concludes with a visual example of a local script's effect being limited to the player's perspective, highlighting the difference between local and server-side actions in a multiplayer setting.

Mindmap

Keywords

💡Roblox

Roblox is an online gaming platform and game creation system that allows users to design their own games and play a wide variety of different types of games created by other users. In the context of the video, Roblox is the platform where the scripting tutorials are focused on, and it is the environment in which the viewer will be developing games.

💡Advanced scripting

Advanced scripting refers to the more complex and sophisticated techniques used in programming within the Roblox platform. The video series is aimed at those who have already completed beginner scripting tutorials and are ready to delve into more complicated topics, such as local scripts and the server-client model.

💡Server-client model

The server-client model is a fundamental concept in networked applications, including multiplayer games like those on Roblox. The server is a central system that manages the game's state and rules, while clients are individual player instances that interact with the game. The video emphasizes the importance of understanding this model for game development on Roblox.

💡Replication

In the context of the server-client model discussed in the video, replication refers to the process by which actions or changes made on the server are mirrored across all client instances. This ensures that all players see the same game state, such as a character's movement, which is crucial for maintaining a consistent gaming experience.

💡Local scripts

Local scripts in Roblox are scripts that execute on the client side and do not affect the server or other players. They are used for actions that should only be visible to a specific player, such as UI elements or local game mechanics. The video demonstrates how local scripts can be used to change the appearance of an object only for the player interacting with it.

💡Client perspective

The client perspective refers to the view of the game from the individual player's point of view. In the video, the distinction between the client and server perspectives is highlighted, showing how different players can have different experiences based on their local scripts and interactions.

💡Server perspective

The server perspective is the view of the game from the central server's point of view. It is used to manage and synchronize the game state across all clients. The video explains how developers can switch between client and server perspectives in Roblox Studio to test and develop their games.

💡Pet Simulator X

Pet Simulator X is an example game used in the video to illustrate how different players can have different experiences based on their progress in the game. It demonstrates how local scripts can affect what players see, such as unlocking new areas or accessing different UI elements.

💡UI (User Interface)

User Interface (UI) in the video refers to the elements on the screen that players interact with, such as buttons and menus. The video uses UI elements like teleport buttons to show how local scripts can create unique experiences for individual players, with different UI elements appearing based on their actions.

💡Workspace

In Roblox Studio, the workspace is the environment where game objects and scripts are created and managed. The video mentions the workspace in the context of creating a part and using local scripts to interact with it, demonstrating how game objects are manipulated within the workspace.

💡Starter Player

The Starter Player in Roblox is a template that defines the default settings for a player when they join a game. The video discusses how scripts, including local scripts, can be added to the Starter Player to customize the player's experience, such as changing the color of an object when stepped on.

Highlights

Introduction to the Roblox Advanced scripting tutorial series, emphasizing the importance of understanding the basics before proceeding.

Explanation of the client-server model as the foundation of multiplayer Roblox games, with a visual aid from the Roblox Developer Hub.

Clarification of the server's role as an overseer controlling the game's events and synchronization among players.

Description of the client as individual players, each with their unique perspective and interactions within the game.

Importance of replication in ensuring all players see the same game state, such as character movements.

Discussion on transmitting data between the server and clients, with examples of local scripts for one-way communication.

In-game demonstration of the client-server model using Pet Simulator X, showing different player perspectives and progress.

Illustration of local-sided features like user interfaces that are unique to each player's experience.

Tutorial on switching between client and server perspectives in Roblox Studio for game development.

Introduction to creating local scripts in Roblox Studio, with an example script that prints 'Hello World'.

Explanation of how local scripts run only on the client's side, not being replicated to the server.

Creation of a part in the game that changes color when touched by a player, demonstrating client-side scripting.

Use of 'wait for child' to ensure the part is loaded before the local script attempts to reference it.

Visual demonstration of a local script changing the part's color only on the client's screen, not affecting other players.

Conclusion summarizing the basics of local scripts and the client-server model, with a teaser for future tutorial topics.

Transcripts

play00:00

hey thanks for stopping by welcome to the first  episode of my Roblox Advanced scripting tutorial  

play00:07

series and if you haven't checked out my beginnner  scripting tutorial guide I made a few months back  

play00:12

then I would highly suggest you watch that one  first before watching this one because we're  

play00:17

going to be uncovering more complicated and more  advanced topics in regards to Roblox scripting  

play00:23

so if you think you're ready then you're basically  on the right track to becoming a a top tier Roblox  

play00:28

developer and I figured for the first episode I  think it would be important to discuss about local  

play00:33

scripts and the server client model because you're  going to be knowing about this model for basically  

play00:40

the entire time you're going to be developing  games on Roblox so this is going to be a very  

play00:44

important one so any Roblox game regardless of  whether it allows more than one player per server  

play00:50

or not follows a multiplayer model called the  client server model and to understand a little  

play00:56

bit more about the client server model let me turn  your attention to to a drawing that was created by  

play01:03

the Roblox developer Hub and I think this is  a really great drawing so so let's go to that  

play01:08

real quick all right so there's two very important  aspects to know about for the server client model  

play01:13

and the first one we'll be discussing about is the  server the best way I can describe the server is  

play01:18

it's basically a reserved section of any Roblox  game that oversees the whole game itself so if I  

play01:26

just drag this along really quick you can see that  the server can be represented as the game itself  

play01:34

where you can see that there's three players that  are inside of the game and the camera is directed  

play01:40

away from any specific player so it's kind of  like an overseer it kind of oversees the whole  

play01:49

game and it controls everything that happens  with the game so that's essentially the server  

play01:54

but now to describe the client side a client  is in the easiest way I can describe cribe the  

play02:00

player itself each individual player so we have  one player that's over here then we have another  

play02:06

player and then we have our third player that's  over here so we have three different players that  

play02:12

all act as clients that are connected to the  server which oversees everything the server is  

play02:19

what controls synchronization among all three  of the players that are inside of the game so  

play02:25

you can see here one of the clients is one of the  players um the camera is directed towards them and  

play02:33

they're seeing every that's happening in the game  from their perspective and that's going the same  

play02:40

way for these other two players so there's three  important things to know about with the server  

play02:45

client model and the first thing is replication  whenever something happens in the server it will  

play02:51

be replicated to be shown in every single player  that are in the server if a player decides to move  

play02:59

their character character then it will show to  other players that this character has also moved  

play03:06

and replication is playing a factor in making sure  that all the players are seeing exactly the same  

play03:15

thing that's happening on the server another  important thing is transmitting data between  

play03:21

the server and also the client so usually if we  want to change something through script where it  

play03:28

will be replicated only to one specific person  and not be shown to other people then we would  

play03:34

use features like local scripts and I'm going to  be showing you how those work in a little bit so  

play03:41

there can be different ways of transmitting data  there can be from one client to the server there  

play03:46

can be from the server to one of the clients  or there can be the server sending data to all  

play03:54

the clients in the server so now that I'm done  explaining how this works let me show you some  

play03:59

in-game examples of how this would actually turn  out all right so I'm in a game in pet Simulator  

play04:05

X and I'm being joined by my ALT account that I  just created so there's one thing to note here  

play04:11

that's quite odd between the perspective  of my account and my alternative account  

play04:17

so on my alternative account you can see that I  haven't unlocked the next area in pet Simulator  

play04:24

X because I need to get 10,000 coins in order  to uh buy the game to get to the next area but  

play04:32

on my main account uh I have lots of progress in  the game already and I already bought the gate uh  

play04:40

to go to the next area so from my perspective  I can see that the gate is not there but then  

play04:47

on my alternative account that's new they cannot  access the next area until until they get 10,000  

play04:53

coins another example of local sided features is  user interface so for instance these buttons on  

play05:01

the left side you have hoverboard teleport Auto  settings if I click on one of these it'll show a  

play05:08

popup of a little panel that shows all the places  I can teleport to now if I go to my ALT account  

play05:16

on their side of the screen they can't see the  popup for the teleport it's Unique to them only  

play05:22

if they click the button so my ALT account can  click the button to show the teleport but then  

play05:29

on my main I can X out of this and open up the  pets panel and on my alternative account it's  

play05:38

still going to be on the teleport page so that's  another big example of client sided gameplay all  

play05:44

right so now we know having a good understanding  of the client server model is really powerful and  

play05:50

it's something we're really going to have to take  into account for anything we do when we're trying  

play05:55

to develop something whether we want to show  something specific to a specific player or if  

play06:00

we want to show something to all players it can  be replicated throughout uh the entire game and  

play06:06

so that's always just something that you should  keep in the back of your mind but now what I want  

play06:10

to do is show you how to access these different  modes when you're creating on Roblox so if we hit  

play06:18

test up here and then hit play then our character  should be joining into the game like normal as  

play06:23

a client so here's our character here um and in  order to flip between what you see on the client  

play06:31

versus what you see on the server we're going to  go up here uh inside of the test ribbon ribbon as  

play06:37

usual uh there's going to be a monitor here saying  current client so this is the current perspective  

play06:43

that we're seeing in the Roblox Studio window  which is our player right here if we click on  

play06:49

it we can actually see that the perspective has  changed to the server now so our camera is now on  

play06:57

the default location for the the server when the  game starts up and as we can see we can freely  

play07:03

move around in this server much like how we make  games in Roblox Studio using the studio 3D world  

play07:11

looking um map so if I click it again then it  should go back to the perspective of the player  

play07:19

and we should be able to move around freely like  so so that's how you flip between the client and  

play07:25

server perspective when you're creating a game  on Roblox and to give you a little bit more of  

play07:30

an understanding of what the perspective looks  like between the two so let's hit stop and now  

play07:37

what we're going to do is create our first local  script on Roblox we create scripts to be able to  

play07:43

give it instructions and make it do what we want  to do in Roblox but there's going to be a lot of  

play07:49

times where we want the things to happen only  within a specific player and not have it be  

play07:55

replicated onto the server and this is where local  scripts come in so on the right side if you have  

play08:02

your Explorer window pulled up I assume you have  uh if you don't have it pulled up then you go to  

play08:06

the view tab up here and then the Explorer and  properties tab should both be here so let me just  

play08:12

open both of these back up um and make sure you  also have your output down here so we can see the  

play08:17

results that we're about to print out so I'm just  going to right click our output and then clear it  

play08:22

uh so then let's create our local script on our  Explorer let's scroll down a little bit and on our  

play08:29

starter GUI we're going to hit the plus sign and  then we're going to search for a local script and  

play08:35

this is what it should look like so let's click  that and then we see that it brings up the script  

play08:42

editor and this pretty much looks exactly the  same as you would see when you insert a normal  

play08:48

script but this time this acts as a local script  so we're not going to change anything here we're  

play08:53

going to leave this as print hello world we're  going to go back to our game we're going to hit  

play08:58

test and then hit play so then what should happen  is that we should see in the output uh hello world  

play09:07

just like how we normally would in a uh regular  script but here's the interesting thing if we  

play09:14

hit current client and switch over to the server  we can see that hello world is still here but if  

play09:23

you see this colorcoded pattern here you can see  that there's actually a color here that's blue  

play09:29

and then down here is a color that's green so  whenever you see an output down here where the  

play09:35

color is highlighted to be blue that means that  that this little line of code ran on the client  

play09:42

and not the server so green means that it ran on  the server but in this case our local script ran  

play09:49

on the client as soon as one player joined the  game that's when it decided to print out onto the  

play09:58

output let's now make something that will only run  on the client side and not have it be shown on the  

play10:04

server so we're going to create a part where when  a player steps on it it will print out a bunch of  

play10:10

stuff in the output but only on the client so with  our script that we created let's actually disable  

play10:16

this uh we're not going to be using this for the  rest of the tutorial and let's insert a part so  

play10:21

let's go to model up here and then let's hit part  to insert a new part into the workspace so let's  

play10:28

just drag this along here let's change the scale  of it a little bit and let's change the color of  

play10:35

the part down here inside of properties and let's  change the brick color to Yellow for instance um  

play10:43

and now what we'll do is we'll go down here to  starter player in the Explorer so open this up  

play10:50

a little bit and you will see a section called  starter character scripts so let's hit the plus  

play10:56

sign here and let's create a new local script  and then let's delete this code that's been  

play11:04

given to us by default so first what we'll do is  make reference to the part we'll say local part  

play11:11

equals game. workpace do part so that will make  reference to the part that we just created and now  

play11:19

we'll add a touched event to that part so we'll  say part. touched colon connect open parenthesis  

play11:29

function open parentheses close parenthesis let's  also delete this last line here enter and then we  

play11:36

will say print and then in quotations we'll say  like some random mumble jumble here okay so now  

play11:44

let's go back to the game we'll hit test and we'll  hit play okay so it looks like I got an error here  

play11:50

uh saying that part is not a valid member of  workspace what ended up happening was that  

play11:55

the part didn't load in fast enough to catch that  there was a part in the server so so we're going  

play11:59

to have to wrap this around in a wait for child so  let's delete part here and after workspace we'll  

play12:07

say colon wait for child and make sure uh you  have the case sensitivity correctly then we'll  

play12:14

uh say open close parentheses and inside of here  in quotes we will say part so now this is going to  

play12:20

force the script to wait until part is loaded into  the game so that we can actually run whatever is  

play12:26

down here so let's touch this and as you can see  on the client the part is printing out all this  

play12:33

mumble jumble random nonsense this stuff isn't  being printed out on the server now it may not be  

play12:39

as clear to you because the only thing we can see  here is the color difference let's do something  

play12:45

more visual so we can actually understand it more  so let's hit stop go back to our local script and  

play12:52

instead what we'll do is we will change the color  of the part when we step on it so let's delete  

play12:58

this print statement here and let's try to write  a line that changes the color of the part so we'll  

play13:05

say part do brick color equals brick color. new  and then in parentheses right here we will put in  

play13:17

some quotes and say really red so now let's go  back into the game and hit play so that we can  

play13:26

see our expected result that has come about with  our script so here we are and once we step on this  

play13:33

plate then it should change the color to Red so as  you can see the color has now changed to red but  

play13:39

if we change our client to the server we can still  see that the color is yellow because we created  

play13:47

a local script that can only show what happens  with this execution when this specific player  

play13:55

touches this part it will only show it happening  on on their screen and not be replicated to every  

play14:02

other player that plays the game like if you just  imagine that there's going to be another player  

play14:06

here another player here and then there's another  player here they're going to see that the part is  

play14:12

still yellow even though you stepped on it and the  color is now red but only you see the part being  

play14:20

red not anybody else so that's pretty much that  so that's pretty much the basics of local scripts  

play14:27

and the server client model I will be going more  into detail about these about local scripts when  

play14:33

we tackle tools that require the starter pack uh  and also gys when I start my guy tutorial series  

play14:40

and things like that but this episode served as an  introduction to local scripts and the server and  

play14:46

client sided models so I think I've done enough to  show that for this episode all right that's going  

play14:50

to be it for this episode thanks for watching  and I will see you in the next episode take care

Rate This

5.0 / 5 (0 votes)

Related Tags
Roblox ScriptingAdvanced TutorialClient-ServerGame DevelopmentLocal ScriptsServer ControlPlayer PerspectiveMultiplayer ModelScript ExamplesGame Mechanics