Multiplayer: a race with friends - Newly guides

Build a short course, turn multiplayer on, and write a finish line that announces who got there first. Then race the class.

One world, many players

When multiplayer is on, everyone who opens your link is in the same world, each with their own character. Your scripts run for each player. Today you'll build a race and run it with the class.

1. Build the course

A start pad, a path with two jumps, a wide part at the end called Finish. Keep it short: about 20 seconds to run. Add a TextLabel on screen called Clock.

2. The finish line

Add a Script to Finish:

local finish = script.Parent
local clock = game:GetService("StarterGui"):FindFirstChild("Clock", true)
local started = os.clock()
local done = false

task.spawn(function()
	while not done do
		clock.Text = string.format("%.1f s", os.clock() - started)
		task.wait(0.1)
	end
end)

finish.Touched:Connect(function(other)
	if done or not other:IsA("Player") then return end
	done = true
	local players = MultiplayerService:PlayerCount()
	clock.Text = string.format("Finished in %.1f s, %d racing", os.clock() - started, players)
end)

Press Play and run it yourself. Does the clock stop on the pad?

3. Race someone

  1. Press Publish.
  2. In your world's settings, turn Multiplayer on.
  3. Send the link to a partner. They open it; you both press Play. You're in the same world.

4. Fix one thing

Something went wrong. It always does. A jump was too far, you could skip a section, the spawn was facing the wrong way. Fix one thing, publish again, race again.

Done when

Open on Newly