Making a place only have one server

Hi all,

I’m looking for a way to make sure all of my experience’s players end up in the same server of a specific place. That is to say, I only want one server open; and if that server fills up, players would need to queue for the server.

The start place is a menu, so this doesn’t need to be applicable to the place players join; rather, it would be a server of a place that they reach through in-experience teleportation.

The reason for this is a third-party API with a strict access limit; rather than needing to find a way for servers to talk to each other and make sure they aren’t overloading the API, I’m hoping I can just make sure there’s never more than 1 server so it isn’t an issue.

Is there a way to do this?


Edit : You would also need a big server size

This still allows other servers to open if the first server becomes full. I need a way to make sure that there can never be more than one server.

Maybe you can try kick all the other players in the other server, but I don’t know how to check if there is already a server.

I’ve never used this before, but perhaps take a look at MemoryStoreService. It allows for communication between servers. It might allow your 1 server place to give information to your menu place (e.g. if the server is full or not).

1 Like

I know its 2024 but I needed this myself and came up with this;
it uses a global datastore which does true or false, determining whether it should stay open or close

local DataStoreService = game:GetService("DataStoreService")
local ServerLockDataStore = DataStoreService:GetDataStore("ServerLockDataStore")

local ServerLockKey = "IsServerLocked"

function shutdown()
	game.Players.ChildAdded:connect(function(h)
		h:Kick("Server already active")
	end)
	for _,i in pairs (game.Players:GetChildren()) do
		i:Kick("Server already active")
	end
end

local success, isLocked = pcall(function()
	return ServerLockDataStore:GetAsync(ServerLockKey)
end)

if success and isLocked then
	print("Server is already running. Shutting down.")
	shutdown()
else
	local success, _ = pcall(function()
		ServerLockDataStore:SetAsync(ServerLockKey, true)
	end)

	if not success then
		warn("Failed to lock the server.")
	else
		print("Server is now running.")
		
		game:BindToClose(function()
			local success, _ = pcall(function()
				ServerLockDataStore:SetAsync(ServerLockKey, false)
			end)

			if not success then
				warn("Failed to unlock the server.")
			else
				print("Server is now unlocked. Shutting down.")
			end
		end)
	end
end
1 Like