How can I "lock" a server after a game starts?

Hey, I’ve posted about my Rooms remake a lot, and when the game starts what’s supposed to happen is the server needs to lock. So no players can join the server where the game has started. It works but not as intended.

image

it doesn’t take you to a separate server, it’s the same one but it just kicks whoever joins and doesn’t create a new one. If that makes sense

here’s the code we wrote for it, as an attempt

Code
script.Parent.Door.MainDoor.ProximityPrompt.Triggered:Connect(function()
	if DoorStatus == "Closed" and Debounce == false then
		
		print('[ SERVER ]: Server has been locked, have fun')

		game.Lighting.ClockTime = 0
		game.Lighting.Brightness = 0
		game.Lighting.FogColor = Color3.fromRGB(36, 34, 30)
		game.Lighting.FogEnd = 250
		
		workspace.Music:Stop()
		workspace.Ambient:Play()

		local function onPlayerAdded(player: Player)
			player:Kick('The game has already started!')
		end
		
		Players.PlayerAdded:Connect(onPlayerAdded)
		
		game.ServerStorage.Bindables:WaitForChild("BuildRoom"):Fire()
		
		script.Parent.Door.MainDoor.ProximityPrompt:Destroy()
		Debounce = true
		DoorMain.Open:Play()
		TweenModel(script.Parent.Door, script.Parent.ToGoPos.CFrame)
		DoorStatus = "Opened"
		Debounce = false
	end
end)

any help is appreciated, thank you in advance

There isn’t really a way to do this. Could you just teleport them (the players you kick out OR the players joining the game) to a different reserved place, similar to a lobby system?

1 Like

i could try using reserved servers. I recall some old code I wrote for it, but that was to teleport into a place inside the game. Like a match.
How would it apply to this case in particular?

Have you tried making the player rejoin the game by using TeleportService:Teleport(game.PlaceId,player). However it would be better to have a lobby with the list of servers which are currently in match and which are not thus letting players join the server.

Or you could have a list of servers which you could join, and teleport the player to one of them. Region of the server in relation to the player’s region is a concern tho.

1 Like

server list could work, do you have any ideas as to how i could pull it off?

You can use MessagingService, when a new server is created you can communicate with other servers to add the server into their list of servers. Further you could also communicate with other servers whenever a round starts or end to indicate whether the server can be joined.

1 Like

i’d need a bit of guidance, i know nothing about MessagingService.

https://developer.roblox.com/en-us/api-reference/class/MessagingService
and you can watch this video How to Make a SERVER LIST | HowToRoblox - YouTube

1 Like