Roblox Studio · Lesson 17

Client vs. Server: Who Sees the Changes

Run Script and LocalScript respectively, and use two player windows to observe the difference between shared scenes and personal effects.

10–15 years old 75 minutes Client / Server Hands-on practice Testing and Saving

Course overview

Why can two people see different colors in the same game?

Think of the server as a referee that holds common rules, and think of the client as everyone's own screen and input device. They send information to each other, but they are not exactly the same computer.

This lesson is an observation experiment. You will see the shared signs created by the server, then the personal tags added to the local script, and finally compare the two player windows.

01 · BEFORE

Before starting

Know the difference between Script and LocalScript. Create a new Lesson17 and get familiar with Output.

02 · MAKE

Your work

A piece of server is changed to a green SharedBlock, and each client has a unique name interface.

03 · CHECK

Complete flag

Both players see the shared green block, and their respective interfaces display their names; they can distinguish between Server and Client output.

Studio client test perspective screenshot
Figure 17-1: Official client perspective screenshot: The client contains the player's personal display and operation status.Roblox Creator Documentation · CC BY 4.0 · The original image has not been modified · Description of the permit

Learning route

Prepare first, then do it; after seeing the result, remember to save it.

Every time a small step is completed, it is tested. Say what you expect to see first, and then use Play and Output to check it. Don't rush to write all the code at once.

1

01· First draw two operating positions

Ordinary Scripts in ServerScriptService are run on the server. The LocalScript in StarterPlayerScripts will be copied to each player's PlayerScripts and run on their respective clients.

2

02· Server changes to sharing scenario

The server turns the shared square green, and the client receives this change. Normal network replication takes time and it should not be assumed that it will arrive at the exact same time as another message.

3

03·Each client has its own LocalPlayer

Players.LocalPlayer represents the player who is using this screen on the client side. The server manages many players at the same time, and there is no "only me".

4

04 · Open two clients for comparison

Select Server & Clients in Studio test mode, set up two clients and start. Different versions of the button may have different locations. Find them by function name instead of memorizing the icon coordinates.

5

05 · Decide where a feature should live

The personal performance of cameras, flashcards, button feedback, etc. is usually handled by the client.

Step by step

01· First draw two operating positions

Ordinary Scripts in ServerScriptService are run on the server. The LocalScript in StarterPlayerScripts will be copied to each player's PlayerScripts and run on their respective clients.

This lesson keeps the map small and uses the default small Baseplate test. You don't need to modify your account, publishing permissions, or cloud settings.

  1. Create Anchored SharedBlock, Size=8, 4, 4, Position=0, 2, -12.
  2. Create ServerScriptService>SharedWorld(Script).
  3. Expand StarterPlayer > StarterPlayerScripts and create MyView (LocalScript).

Step by step

02· Server changes to sharing scenario

The server turns the shared square green, and the client receives this change. Normal network replication takes time and it should not be assumed that it will arrive at the exact same time as another message.

Adding [Server] in front of print is just our own reading tag. The real execution source depends on the context of Output.

  1. Put the code into SharedWorld.
  2. When playing, observe that the box turns green and there is a server message in Output.
ServerScriptService > SharedWorld(Script)Luau
local block = workspace:WaitForChild("SharedBlock")
block.Color = Color3.fromRGB(70, 220, 150)
print("[Server] SharedBlock is green")

Step by step

03·Each client has its own LocalPlayer

Players.LocalPlayer represents the player who is using this screen on the client side. The server manages many players at the same time, and there is no "only me".

The following code is used to create a simple interface, and there is no need to use the file of Lesson 15. It only shows the identity and does not copy the same name on other people's screens.

  1. Put the code into MyView.
  2. Note that the Parent of ScreenGui is the PlayerGui of the current player.
  3. After Play, read the name in the upper left corner and find the corresponding Client output.
StarterPlayer > StarterPlayerScripts > MyView(LocalScript)Luau
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local gui = Instance.new("ScreenGui")
gui.Name = "MyViewGui"
gui.ResetOnSpawn = false
local label = Instance.new("TextLabel")
label.Size = UDim2.fromOffset(300, 56)
label.Position = UDim2.fromOffset(16, 16)
label.TextSize = 20
label.Text = "我的屏幕:" .. player.Name
label.Parent = gui
gui.Parent = player:WaitForChild("PlayerGui")
print("[Client] This is", player.Name)

Step by step

04 · Open two clients for comparison

Select Server & Clients in Studio test mode, set up two clients and start. Different versions of the button may have different locations. Find them by function name instead of memorizing the icon coordinates.

View the two client and server perspectives respectively. Don't mistake two client windows for two servers. The game still only has shared servers for this round of testing.

  1. Verify that both players see the green SharedBlock.
  2. Confirm that the two labels display their player names respectively.
  3. View player records in Server Explorer; client-specific interfaces should not be treated as server authoritative data.
Server perspective screenshot in the same test
Figure 17-2: Screenshot from the official server perspective: observe the common scene after switching and understand that the server and the client are not in the same running state.Roblox Creator Documentation · CC BY 4.0 · The original image has not been modified · Description of the permit

Step by step

05 · Decide where a feature should live

The personal performance of cameras, flashcards, button feedback, etc. is usually handled by the client.

If the client wants to do something that will affect the common rules, it needs to make a request. The next lesson will use RemoteEvent to hand this request to the server for inspection.

  1. Write Client or Server respectively for "Open prompt card, obtain gold coins, change camera, receive treasure box".
  2. End all test clients with End Session.
  3. Save the project and compare it with a screenshot of two players to avoid leaving a test window that takes up resources.

Homework

It's your turn to change and make your own version.

1 Draw a running map

Put Workspace, ServerScriptService, and PlayerGui in the server or client location you understand.

2 Personal welcome message

Add a welcome message of your own to the local tag, but keep the player name dynamically read.

3 Selection: Different displays

Check the respective LocalPlayer.UserId in the two test clients. It is only observed in the Output and is not used to collect real personal information.

Completion criteria:First verify the work in Playtest, then click Stop and save it as "Initials_Lesson17" or the corresponding Homework copy; do not overwrite the runnable version of the previous lesson.

Exit questions

Answer it yourself first, and then expand on it.

Who is the LocalPlayer in the server?

The server does not have a unique local player, LocalPlayer only makes sense on the client.

Why are the tag names of two people different?

The same LocalScript is run on each client, and each reads its own LocalPlayer.

Who should determine the reward for the gold?

Verified and updated by the server, the client can only make requests or display results.

What to do after the multi-person test is over?

Ends the entire session, closes the test client and saves the editing items.

Explore further

This is where we start when we need to check the data.

The text code can be copied directly. First confirm the script type, placement, and whether this code is a complete version or a small experiment; do not run multiple versions of the same script superimposed. The source of the interface reference picture has been marked. The object names in the picture may be different from those in this lesson. Please refer to the operation steps.

Download the code and placement instructions for this lesson