How to make the oldest running server be a "host" server?

Hello, I am trying to make the oldest server in my game be a “host”/Main server. I am using @5uphi’s solution from this devforum post: How to find the oldest server in your game? - Help and Feedback / Scripting Support - DevForum | Roblox
and I am wondering how I could make it so that only the oldest server will have a script enabled. (Therefor disabling the script in all the other servers that dont have the largest DistributedGameTime.) All help is appreciated, thanks!


You could use os.time() to make messagingservice send the current servers uptime to every other server every ‘multiple of 10 seconds unix time for example’ (Therefore, all the servers will be synced with some having a little bit of time error due to server lag or messaging service delay). Have each server put the other server uptimes in a table every single communication time and then loop through the table of other server uptimes and see if the current server has an uptime larger than all of the other ones.

This could cause some errors if your game runs a lot of servers because messagingservice can only handle so many requests.

1 Like

Oh alr, I may try this. Although I am wondering if it would be possible to fix my current script I want to disable on all servers so that it will send to all servers and will only choose 1 item to send. (This way it won’t have 2 items when there is really1.)

active = false
local items = {"Silver axe", "Auction2", "Auction3", "Auction55"}

while wait(math.random(5,10)) do
	if game.ServerStorage.ItemsCount.Value < 3 then	
		local message
		game:GetService("MessagingService"):SubscribeAsync("SendNewAuction-defKey", function()
			local rand = math.random(1, #items) 
			local obj = items[rand]

			message = obj
			local clone = game.ServerStorage.AuctionItems.Template:Clone()
			clone.Parent = game.ServerStorage.AuctionItems
			clone.Name = obj
			game.ServerStorage.ItemsCount.Value += 1
			clone.Serial.Value = game:GetService("HttpService"):GenerateGUID(false)
			--[[for i,v in pairs(game.Players:GetPlayers()) do
				for ii,vv in pairs(v.PlayerGui.ScreenGui.Frame.Buttons:GetChildren()) do
					if vv.Name ~= "Template" and not vv:IsA("UIGridLayout") then
			for i,v in pairs(game.Players:GetPlayers()) do
				local guiClone = v.PlayerGui.ScreenGui.Frame.Buttons.Template:Clone()
				guiClone.Name = clone.Name
				guiClone.Parent = v.PlayerGui.ScreenGui.Frame.Buttons
				guiClone.Visible = true
				guiClone.Text = clone.Name
		game:GetService("MessagingService"):PublishAsync("SendNewAuction-defKey", message)
	elseif game.ServerStorage.ItemsCount.Value > 3 then

I’m really sorry. I’m not that good at reviewing, looking at, and fixing up code. I think I do better with giving ideas.

However, I’m wondering why you’re using subscribe async inside a while loop because that works as a function and will fire whenever it gets notified by messagingservice. It doesn’t need a loop to keep running.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.