hello dev forum members, im here to ask for help for the servers list i got (template used from youtube, yeah sorry for that because tbh i dont know how to do server list)
I want to do that if you already made the server, and you will create new one, previous will destroy. Also if server’s players is 0 it will shutdown. How to do that?
(btw also wondering how to edit server, like max players or values inside of the server if possible)
(code below)
local DSS = game:GetService("DataStoreService")
local TS = game:GetService("TeleportService")
local ServerAccessCodesDS = DSS:GetDataStore("ServerAccessCodesDS.2")
local LocalOwnedServersDS = DSS:GetDataStore("LocalOwnedServersDS.2")
local GlobalPrivateServerDS = DSS:GetOrderedDataStore("GlobalPrivateServerDS.2")
local ServerNamesDS = DSS:GetDataStore("ServerNamesDS.2")
local PrivateServerOwnerIdDS = DSS:GetDataStore("PrivateServerOwnerIdDS.2")
local ServerInfoDS = DSS:GetDataStore("ServerInfoDS.2")
local PlaceId=game.PlaceId
local menu = script.Parent.Parent
local createServerButton = menu.CreateFrame.Create_Button
local plr = menu.Parent.Parent
local psid = game.PrivateServerId
local servers = {}
pcall(function()
for i,v in pairs(LocalOwnedServersDS:GetAsync(plr.UserId) or nil) do
table.insert(servers, v)
print(plr.Name.." Private Server Codes = "..v)
end
end)
function GenerateServerInviteCode()
while true do
local code = math.random(0,1999999999)
if not ServerNamesDS:GetAsync(code) then
return code
end
end
end
function SortGlobalPrivateSeversAsync()
local pages = GlobalPrivateServerDS:GetSortedAsync(false, 100)
for i,v in pairs(menu.ServersFrame.ScrollingFrame:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
local data = pages:GetCurrentPage()
for i,v in pairs(data) do
warn(v.value, v.key)
wait(.2)
local ServerInfoDictionary = ServerInfoDS:GetAsync(v.key)
local ServerFrameClone = script.Template:Clone()
ServerFrameClone.Parent = menu.ServersFrame.ScrollingFrame
ServerFrameClone.Players.Text = v.value.."/"..ServerInfoDictionary.ServerPlayers
ServerFrameClone.MadeBy.Text..=" "..ServerInfoDictionary.PlayerName
ServerFrameClone.ServerName.Text = ServerInfoDictionary.ServerName
local code312 = ServerAccessCodesDS:GetAsync(v.key)
ServerFrameClone.JoinButton.MouseButton1Click:Connect(function()
local code = ServerAccessCodesDS:GetAsync(v.key)
TS:TeleportToPrivateServer(PlaceId, code, {plr})
end)
end
end
createServerButton.MouseButton1Click:Connect(function()
local code, id = TS:ReserveServer(PlaceId)
local NewJoinCode = GenerateServerInviteCode()
GlobalPrivateServerDS:SetAsync(id, 0)
ServerAccessCodesDS:SetAsync(id, code)
PrivateServerOwnerIdDS:SetAsync(id, plr.UserId)
local ServerInfoDictionary = {
ServerName = script.Parent.GetServerName:InvokeClient(plr),
ServerPlayers = script.Parent.GetServerPlayers:InvokeClient(plr),
PlayerName = script.Parent.GetPlayerName:InvokeClient(plr),
}
ServerInfoDS:RemoveAsync()
ServerInfoDS:SetAsync(id, ServerInfoDictionary)
table.insert(servers, NewJoinCode)
local success, errorMessage = pcall(function()
LocalOwnedServersDS:SetAsync(plr.UserId, servers)
end)
SortGlobalPrivateSeversAsync()
spawn(function()
local pages = GlobalPrivateServerDS:GetSortedAsync(false, 100)
local data = pages:GetCurrentPage()
for i,v in pairs(data) do
local code312 = ServerAccessCodesDS:GetAsync(v.key)
TS:TeleportToPrivateServer(PlaceId, code312, {plr})
break
end
end)
end)
SortGlobalPrivateSeversAsync()