local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local PlayerStore = DataStoreService:GetDataStore("Players")
function getNumberOfPlayers()
return #Players:GetPlayers()
end
if getNumberOfPlayers() == 0 then
-- i don't know what to do from this point
end
Players.PlayerRemoving:Connect(function()
if getNumberOfPlayers() == 0 then
-- and here you can PublishAsync the server that have just deleted
end
end)
--and when it publish you can subscribe async and get that server that have already deleted
messagingService:SubscribeAsync("Servers", callbackFunction)
Just use MemoryService like I linked earlier. Every 5 second intervals, send data with the JobId and player list, and have it set to degrade after 5 seconds. Then from the title screen, read from the list of MemoryStore entries and load UI based off of that. If the server closes, it will clear after 5 seconds. Or you can manually remove it after the final player leaves. Though the same concept applies to a DataStore in that case.
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
function getNumberOfPlayers()
return #Players:GetPlayers()
end
Players.PlayerRemoving:Connect(function(player)
if getNumberOfPlayers() == 0 then
MessagingService:PublishAsync("Server closed!", 'Player-'..player.UserId)
MessagingService:SubscribeAsync("Servers", callbackFunction)
end
end)
I guess you should to send there you indentify of server like it’s name or smth
and then in the callbackFunction you should to delete if from the list of servers or just delete if from the array of servers if you have one.
and put subscribe async out of check
Also i don’t know how you indentify those servers that’s why i can’t say what should you send in PublishAsync.
local function callbackFunction(name_or_indentify_of_server_here)
-- delete you server from that list of servers
end
Players.PlayerRemoving:Connect(function(player)
if getNumberOfPlayers() == 0 then
MessagingService:PublishAsync("Server closed!", "Name or indentify of server")
end
end)
MessagingService:SubscribeAsync("Servers", callbackFunction)
Something like this (this script is in the place the player is teleporting to)
local MemoryStoreService = game:GetService("MemoryStoreService")
local ServerClosed = MemoryStoreService:GetQueue("ServerClosed")
local Players = game:GetService("Players")
function getNumberOfPlayers()
return #Players:GetPlayers()
end
Players.PlayerRemoving:Connect(function(player)
if getNumberOfPlayers() == 0 then
local addSuccess, addError = pcall(function()
ServerClosed:AddAsync("Server closed!")
end)
if not addSuccess then
warn("Err!")
end
end
end)
But how would I make this destroy the server frame?
I meant that you would constantly send updates saying that the server does exist, while including the server information in said update. Once the server closes, the memorystore will automatically clear and memorystores are temporary. You set how long you want them to last.
Here, this is the exact code I used for the actual game server:
local MS = game:GetService('MemoryStoreService')
local P = game:GetService('Players')
local serverList = MS:GetSortedMap('serverList')
local closing
game:BindToClose(function()
serverList:RemoveAsync(tostring(game.JobId))
closing = true
end)
repeat
local server = {}
for _,v in pairs(game:GetService('Players'):GetChildren()) do
if not v:GetAttribute('Hide') then
table.insert(server,v.UserId)
end
end
if not closing then
pcall(function()
serverList:SetAsync(tostring(game.JobId),server,15)
end)
end
task.wait(5)
until false
This is the code I run on the title screen:
local MS = game:GetService('MemoryStoreService')
local serverList = MS:GetSortedMap('serverList')
local R = game:GetService('ReplicatedStorage')
local event = R:WaitForChild('Request Teleport')
local TP = game:GetService('TeleportService')
local list = R:WaitForChild('List')
event.OnServerInvoke = function(p,a,b)
warn('Teleport request obtained:\n'..tostring(p)..'/'..a..'/'..tostring(b))
if not workspace:GetAttribute('ServerLock') and a == 'Auto' then
TP:Teleport(4968816126,p)
local result
result = TP.TeleportInitFailed:Connect(function(player)
if player == p then
result:Disconnect()
return
end
end)
elseif a == 'JobId' and b then
TP:TeleportToPlaceInstance(4968816126,b,p)
local result
result = TP.TeleportInitFailed:Connect(function(player)
if player == p then
result:Disconnect()
return
end
end)
end
end
repeat
list:ClearAllChildren()
for _,v in pairs(serverList:GetRangeAsync(Enum.SortDirection.Ascending,200)) do
local server = Instance.new('Folder')
server.Name = v['key']
for _,q in pairs(v['value']) do
Instance.new('Folder',server).Name = q
end
server.Parent = list
end
task.wait(5)
until false
Ignore the extra code, I was also handling other things in there as well. Plus this code is a bit older, though it still functions as intended.
i dont think you can destroy a server because the server is not accessible due to us for certain reasons, if it somehow was roblox wouldnt have working games anymore
I made a testing place with vip servers system one day ago.
If you need i can show you the code.
Ps: Q to open gui and click create vip server also don’t mind that join button it doesn’t work also vip servers are free) Testing vip servers system
There were some problems with the owner of reserved server that’s why i made player that join server first to be the owner of reserved server.Because when you are on server you can’t get that it is the server that you have even if you have it’s code.
Edit:
Owner of the server is that one who created it nvm.
the was the problem with PrivateId of that server because i couldn’t indentify that the reserved server is that server that you reserved.