How client-server architecture works on Roblox — Transcript
Full transcript
- 0:00This video is for developers who have
- 0:01experience with other game engines, but
- 0:03are new to Roblox. If you've used other
- 0:06engines, adapting to Roblox's
- 0:07client-server architecture can require
- 0:09[music] a bit of a shift in mindset.
- 0:11Let's discuss why.
- 0:13Hey everyone, it's Andrew from Roblox.
- 0:15What I have here is a demo experience
- 0:17generously provided by Mr. Chicken
- 0:19Rocket and Dev Odysseus. It's a
- 0:21twin-stick shooter, a genre that I
- 0:22imagine many of you are familiar with.
- 0:24You shoot skeletons with friends, revel
- 0:26in the chaos, and grab gems. Let's dig
- 0:29into some key features of this
- 0:30experience, and along the way we can
- 0:32talk more broadly about developing on
- 0:33Roblox. It's a lot. I want to cover a
- 0:36lot. We'll talk about the following.
- 0:42Let's start [music] with project
- 0:43architecture. The first, maybe most
- 0:45important point to understand when
- 0:47getting started with Roblox is that the
- 0:48client-server architecture means that
- 0:50the server owns everything. As you build
- 0:54in Studio, what you're looking at is the
- 0:56server's view of the world. [music] The
- 0:57client then gets some subset of that
- 1:00view depending on the situation, and can
- 1:02make its own local-only changes for
- 1:03things like the user interface and
- 1:05visual effects. [music]
- 1:07This architecture means there are a
- 1:09whole bunch of places to put scripts. We
- 1:11have not one, but two other videos on
- 1:13this subject. Check them out if you want
- 1:15to get into the nitty-gritty. The basics
- 1:17are that server scripts go in server
- 1:19script service, and client scripts go
- 1:21[music] in replicated storage with a run
- 1:23context of client. Shared module scripts
- 1:26also go in replicated storage.
- 1:28As we switch between the client and the
- 1:30server in Studio, you can see right away
- 1:32that the contents of server script
- 1:34service and server storage just aren't
- 1:36on the client. The difference is even
- 1:38more stark if you test an experience
- 1:40that uses streaming and enable the free
- 1:42cam with shift P. In addition to not
- 1:44having everything you saw on the server
- 1:46while editing the experience, [music]
- 1:48you can see here that the client only
- 1:49has a subset of the whole workspace.
- 1:51When we start building, the first step
- 1:53is to give ourselves some objects to
- 1:55[music] work with. Mr. Chicken Rocket
- 1:57calls this mental scaffolding, a term I
- 1:59love, but the more prosaic way to think
- 2:01about it is that games are all about
- 2:03interactivity,
- 2:04>> [music]
- 2:04>> and it's hard to add interactivity to
- 2:06objects that don't exist. If you want to
- 2:08build a twin-stick shooter with a
- 2:10procedural layout and destructible
- 2:11objects, the first step is to build some
- 2:14rooms.
- 2:15Before we start scripting, let's get
- 2:17comfortable. You can absolutely use the
- 2:19built-in script editor, but if you're an
- 2:21experienced developer, you probably have
- 2:23a preferred [music] text editor. Taking
- 2:25the time to set up script sync means
- 2:27that you can use your favorite editor
- 2:28and your favorite coding tools. Here
- 2:31I've synced everything to my local disk
- 2:32[music] and open the project in Cursor.
- 2:35Because it's on my local disk, I can use
- 2:36Git or any other version control system.
- 2:39Depending on how deep you are down the
- 2:41AI rabbit hole, and and listen, I'm not
- 2:43judging either way, you might also want
- 2:45to hook up the Studio MCP server to
- 2:47Claude.
- 2:48You might be tempted to start putting
- 2:49scripts directly onto objects in the
- 2:51workspace, but it inevitably leads to a
- 2:53maintenance nightmare as you start
- 2:55duplicating models. Instead, tag the
- 2:57parts you need to reason around and use
- 2:59the collection service to gather them up
- 3:01so you can work with them in a single
- 3:03place. Rather than running every frame,
- 3:05code in Roblox tends to be more
- 3:07event-driven, so you listen for changes
- 3:09>> [music]
- 3:10>> and then run some code.
- 3:11Speaking of events, communication
- 3:13between the client and the server occurs
- 3:16using what are called remote events. We
- 3:17have a video on this subject, too. Link
- 3:19in the description.
- 3:21Here, the client performs all sorts of
- 3:23work to create a compelling visual for
- 3:24the player. It [music] takes a broken
- 3:26child model within the original model
- 3:28and adds it to a debris table.
- 3:30When a bullet hits the model, the script
- 3:32swaps it for the broken one, [music]
- 3:34unanchors the parts so that physics
- 3:35apply, and then makes them go flying.
- 3:37Give those parts a randomized ejection
- 3:39vector.
- 3:41A simple particle effect then amps up
- 3:43the sense of destruction.
- 3:44Finally, though, the client script
- 3:46notifies the server, "Hey, player one
- 3:48broke this object." using a remote
- 3:50event. In response, the server
- 3:52replicates the action to all other
- 3:53clients, spawns loot only for player
- 3:56one, and then destroys the object. The
- 3:58final situation is very instructive. On
- 4:01player one, we see debris and a few
- 4:03gems. On player two, just the debris,
- 4:05but critically, it's [music] different
- 4:06debris due to the random nature of the
- 4:08client code. On the server, we don't see
- 4:10anything at all because the server is
- 4:12keeping track of state, not visuals.
- 4:15There's also general housekeeping, most
- 4:17of which uses the player and character
- 4:19events. When a player joins for the
- 4:21first time, initialize their data. If
- 4:23they're returning, load their data from
- 4:25a data store. Manipulate that data over
- 4:27the course of their session and save it
- 4:28when they leave. Do you plan to
- 4:30implement your own character solution or
- 4:32use default avatars?
- 4:34Will players use the built-in spawn
- 4:36system, [music] or do you need to create
- 4:37your own? It's not the most exciting
- 4:40scripting work in the world, but it
- 4:41creates the
- 4:42testable skeleton of of your experience.
- 4:45Or whatever metaphor you prefer.
- 4:47There are a couple other key features to
- 4:49mention, but they're situational. First,
- 4:51[music] streaming. If players can see
- 4:53beyond 100 m or so, that's 357 studs in
- 4:57Roblox parlance, you probably want to
- 4:59enable streaming. I mention streaming
- 5:01all the time on this channel and
- 5:02probably need to have my title changed
- 5:04>> [music]
- 5:04>> to chief streaming evangelist, but a big
- 5:06gotcha with streaming is to organize
- 5:08your instances into models and mark them
- 5:10as atomic. Marking models as atomic
- 5:13means that clients get the whole model
- 5:14or none of it, which makes it
- 5:16dramatically easier to reason around the
- 5:18modeling code. Imagine a house streaming
- 5:20in incrementally so you get the walls
- 5:22and the floor, and then a few
- 5:24milliseconds later the roof and the
- 5:25doors, and then the windows follow a
- 5:27quarter second after that. It'd be a
- 5:29nightmare to code around. You want your
- 5:31scripts to be only minimally aware of
- 5:33the part composition of a model rather
- 5:35than having to constantly check to make
- 5:37sure they have everything they need.
- 5:39The other key feature is server
- 5:41authority. If you're designing a
- 5:42competitive multiplayer experience,
- 5:44check out server authority. It prevents
- 5:46entire classes of cheats like fly hacks
- 5:49and speed hacks [music]
- 5:50by not trusting clients to report their
- 5:52position or state. It moves ownership of
- 5:55the player from the client, where they
- 5:56can cheat, to the server, where they
- 5:58can't.
- 5:59It's too much to cover here and still in
- 6:01beta, but I'll link to the documentation
- 6:03in the description, which has three
- 6:05sample games to help you understand the
- 6:06difference in project structure when
- 6:08server authority is enabled.
- 6:11To close things out, let's review two
- 6:12more features from this experience.
- 6:14[music]
- 6:14Procedural generation and
- 6:17gates.
- 6:18As you can see here, our view in
- 6:20building in Studio is quite different
- 6:22from the in-game view.
- 6:24You don't have to do this, of course,
- 6:25but if you want a procedural world, you
- 6:27can create any number of discrete
- 6:28building blocks, and then have the
- 6:30server put them together at runtime.
- 6:32Rather than [music] each client having
- 6:34to do that work locally, they all just
- 6:35get the version the server created.
- 6:37Here, we have a server script that
- 6:39initializes the experience. It passes a
- 6:41desired room count and a random seed to
- 6:44the map gen module. Everything is
- 6:46hardcoded here for demo purposes, but
- 6:48could just as easily be random. [music]
- 6:50The module script starts by taking every
- 6:52room and hallway in the prefabs folder
- 6:54and sticking them into tables so they're
- 6:56easy to work with.
- 6:57After some cleanup, you can see that it
- 6:59adds hallways and rooms until it reaches
- 7:01the desired number. If it runs out of
- 7:03unique rooms, it starts duplicating.
- 7:05Add hallway and room mostly deals with
- 7:07orientation and clearing rooms that have
- 7:10already been used from the table to make
- 7:12sure you don't get the same room over
- 7:13and over due to bad luck with
- 7:14randomization. And voila, a layout. And
- 7:17another, and another.
- 7:19Gates sure seem like they should be
- 7:21easy, but the implementation here shows
- 7:23off the separation of server and client
- 7:25concerns really well. You can see that
- 7:27we have a grill positioned below the
- 7:29map, and when we enter a room, the
- 7:30server sets the closed attribute on that
- 7:32grill to true or false. Then the client
- 7:35takes over.
- 7:36In what you might describe as a
- 7:38suboptimal approach, the client checks
- 7:40every grill once per frame to see if
- 7:42it's current open or closed state
- 7:44differs from the closed attribute that
- 7:45the server set. If the state differs,
- 7:48get the open and closed positions from
- 7:50the grill spot open and grill spot
- 7:52closed attachments, and play that tween.
- 7:55Is there a way to make this process
- 7:56event-driven rather than checking every
- 7:58frame? Probably yes, but but that's game
- 8:01development. Even if we look at it and
- 8:03think we can do better, optimizing
- 8:04[music]
- 8:05this module might not yield any tangible
- 8:07performance gains. We're only going to
- 8:09have a few gates at a time, so it's
- 8:10probably [music] better to just keep the
- 8:12simpler code. We can't let the perfect
- 8:14be the enemy of the good, or the good be
- 8:16the enemy of the
- 8:17You know what? I'm actually going to go
- 8:19back and see if I can rewrite that
- 8:20module.
- 8:22For so much more on how to work within
- 8:23Roblox's client-server architecture,
- 8:25check out the documentation at
- 8:27create.roblox.com.
- 8:29I want to extend a huge thank you to Mr.
- 8:31Chicken Rocket and Dev Odysseus for all
- 8:34their help and support on this video,
- 8:36and an equally large thanks to all of
- 8:37you for watching.
- 8:38See you next time.
About this transcript
This page contains the full transcript of How client-server architecture works on Roblox by Roblox Creators, generated from the public captions YouTube serves with the video. The transcript has 1,716 words across 274 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.