I tried to write a script that does this but it ends up doing nothing. Does anyone have any ability to do this?
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local PlaceId = game.PlaceId
-- Function to teleport a player to the first server
local function teleportToFirstServer(player)
local success, result = pcall(function()
return TeleportService:ReserveServer(PlaceId)
end)
if success then
local reservedServerCode = result
TeleportService:TeleportToPrivateServer(PlaceId, reservedServerCode, {player})
else
warn("Failed to reserve server: " .. tostring(result))
end
end
-- Check if the current server is the first server
local function isFirstServer()
local placeInstance = TeleportService:GetPlayerPlaceInstanceAsync()
if placeInstance then
return placeInstance.PlaceId == PlaceId
else
warn("Failed to get place instance")
return false
end
end
-- Bind to PlayerAdded event to check and teleport players if necessary
Players.PlayerAdded:Connect(function(player)
if not isFirstServer() then
teleportToFirstServer(player)
end
end)
-- Iterate through all existing players and teleport if necessary
for _, player in Players:GetPlayers() do
if not isFirstServer() then
teleportToFirstServer(player)
end
end
I personally wouldn’t recommend it as it is extremely hacky and servers only have a maximum player count of 200 (not sure if the 700 still applies to those enrolled in the beta program). You can try disabling social slots in your place settings instead.
Regardless, if you really need this behavior, you can use game.JobId along with DataStoreService (disabled caching) or MemoryStoreService to check if there’s an existing firstServerJobId. If so, teleport the player using TeleportAsync with a TeleportOptions.ServerInstanceId set to the firstServerJobId. If not, publish the firstServerJobId key to a DataStore with a lastUpdated time or any data structure from MemoryStoreService set to a low expiration. In either choices, you will have to periodically update the key(s) with a BindToClose to clear the key, ensuring you update before the key expires if you are using a data structure from MemoryStoreService.
The advantage of using MemoryStoreService is that it will automatically remove itself from the data structure after the specified expiration (with a maximum of 45 days), meaning in case of a server crash and it is unable to clear the firstServerJobId key, you will not have to resort to a fail-safe method of checking if the lastUpdated time is more than your specified threshold.
If you do this by the way, congratulations! You have just made what is called a session lock, typically used in player data
Incredibly intelligent solution. Thank you, that should be very helpful
I just published a game that gives away 1 free ugc every 30 minutes. However, Roblox is making multiple servers and it’s giving away my ugc every 30 minutes PER SERVER! Even if its hacky I intend to monitor it closely!
If you have a little bit of experience with web APIs, I would recommend using MessagingService along with the games.roblox.com/v1/games/{placeId}/servers/{serverType} API instead for a more safer, controlled giveaway. You can loop through all the places, select a random user, and publishing that to a subscribed topic. I’m not too familiar on how UGC works, but you can probably search if there are UGC related APIs as well, even if it’s for a fail-safe method.