-
What do you want to achieve?
a custom player made server system that are made by players also the servers are always visable -
What is the issue?
i have no idea how i would make players join the server that shows on the server list that joins the same server that others are in when joining
server script:
currently it handles server creation and deleting them
local dataStoreService = game:GetService("DataStoreService")
local teleportService = game:GetService("TeleportService")
local PlayerMadeServerIdData = dataStoreService:GetDataStore("PLayersServersId")
local ServerIdData = dataStoreService:GetDataStore("ServersId")
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
local screenGui = plr.PlayerGui:WaitForChild("ScreenGui")
local Server
local success, data = pcall(function()
return PlayerMadeServerIdData:GetAsync(plr.UserId)
end)
if not success then
print("unable to load")
local retry = 0
while retry < 5 do
success, data = pcall(function()
return PlayerMadeServerIdData:GetAsync(plr.UserId)
end)
if not success then
wait(1)
else
print("data found ",retry)
break
end
end
end
if success then
if data then
Server = data
print("Success")
for i,v in pairs(Server) do
local newframe = script.YourServerTemplate:Clone()
newframe.Parent = screenGui.Frame.PlayerServersFrame
newframe.NameText.Text = Server[i][1]
newframe.JoinCode.Text = Server[i][2]
newframe.Code.Value = Server[i][2]
print("loaded a server")
end
else
print("new player")
end
else
print("error")
end
--load server list
local Server
local success, data = pcall(function()
return ServerIdData:GetAsync("Servers")
end)
if not success then
print("unable to load")
local retry = 0
while retry < 5 do
success, data = pcall(function()
return ServerIdData:GetAsync("Servers")
end)
if not success then
wait(1)
else
print("data found ",retry)
break
end
end
end
if success then
if data then
Server = data
print("Success")
for _,i in pairs(screenGui.Frame.ServerListFrame:GetChildren()) do
if i:IsA("Frame") then
i:Destroy()
end
end
for i,v in pairs(Server) do
local newframe = script.ServerTemplate:Clone()
newframe.Parent = screenGui.Frame.ServerListFrame
newframe.NameText.Text = Server[i][1]
print("loaded a server")
end
else
print("new player")
end
else
print("error")
end
end)
end)
local function refreshservers()
for _,i in pairs(game.Players:GetChildren()) do
local plr = i
local screenGui = i.PlayerGui.ScreenGui
local Server
local success, data = pcall(function()
return ServerIdData:GetAsync("Servers")
end)
if not success then
print("unable to load")
local retry = 0
while retry < 5 do
success, data = pcall(function()
return ServerIdData:GetAsync("Servers")
end)
if not success then
wait(1)
else
print("data found ",retry)
break
end
end
end
if success then
if data then
Server = data
print("Success")
for _,i in pairs(screenGui.Frame.ServerListFrame:GetChildren()) do
if i:IsA("Frame") then
i:Destroy()
end
end
for i,v in pairs(Server) do
local newframe = script.ServerTemplate:Clone()
newframe.Parent = screenGui.Frame.ServerListFrame
newframe.NameText.Text = Server[i][1]
newframe.Code.Value = Server[i][2]
newframe.JobId.Value = Server[i][3]
print("loaded a server")
end
else
print("new player")
end
else
print("error")
end
end
end
game.ReplicatedStorage.CreateServer.OnServerEvent:Connect(function(plr,Text)
local code
local save = {}
local save2 = {}
if #plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren() - 1 == 3 then
print("Max Servers")
else
for _,i in pairs(plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren()) do
if i:IsA("Frame") then
table.insert(save,{i.NameText.Text,i.JoinCode.Text})
end
end
code = math.random(111111,999999)
if table.find(save,code) then
print("code in use")
while table.find(save,code) do
code = math.random(111111,999999)
wait(0.1)
end
else
table.insert(save,{Text,code})
end
local newframe = script.YourServerTemplate:Clone()
newframe.Parent = plr.PlayerGui.ScreenGui.Frame.PlayerServersFrame
newframe.NameText.Text = Text
newframe.JoinCode.Text = code
newframe.Code.Value = code
PlayerMadeServerIdData:SetAsync(plr.UserId, save)
print("saved data")
local Server = ServerIdData:GetAsync("Servers")
if Server then
for i,v in pairs(Server) do
local newframe = script.ServerTemplate:Clone()
newframe.Parent = script.TempServers
newframe.NameText.Text = Server[i][1]
newframe.Code.Value = Server[i][2]
newframe.JobId.Value = Server[i][3]
print("loaded a server")
end
for _,i in pairs(script.TempServers:GetChildren()) do
if i:IsA("Frame") then
table.insert(save2,{i.NameText.Text,i.Code.Value,i.JobId.Value})
end
end
end
table.insert(save2,{Text,code,0})
script.TempServers:ClearAllChildren()
ServerIdData:SetAsync("Servers", save)
refreshservers()
print("saved data")
end
end)
game.ReplicatedStorage.DeleteServer.OnServerEvent:Connect(function(plr,frame)
local NameText = frame.NameText.Text
local Code = frame.JoinCode.Text
frame:Destroy()
local save = {}
for _,i in pairs(plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren()) do
if i:IsA("Frame") then
table.insert(save,{i.NameText.Text,i.JoinCode.Text})
end
end
PlayerMadeServerIdData:SetAsync(plr.UserId, save)
print("saved data")
local save2 = {}
local Server = ServerIdData:GetAsync("Servers")
if Server then
for i,v in pairs(Server) do
local newframe = script.ServerTemplate:Clone()
newframe.Parent = script.TempServers
newframe.NameText.Text = Server[i][1]
newframe.Code.Value = Server[i][2]
newframe.JobId.Value = Server[i][3]
print("loaded a server")
end
for _,i in pairs(script.TempServers:GetChildren()) do
if i:IsA("Frame") then
if i.NameText.Text == NameText then
if i.Code.Value == Code then
table.insert(save2,{i.NameText.Text,i.Code.Value,i.JobId.Value})
end
end
end
end
end
script.TempServers:ClearAllChildren()
ServerIdData:SetAsync("Servers", save)
refreshservers()
print("saved data")
end)
game.Players.PlayerRemoving:Connect(function(plr)
local save = {}
for _,i in pairs(plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren()) do
if i:IsA("Frame") then
table.insert(save,{i.NameText.Text,i.JoinCode.Text})
end
end
PlayerMadeServerIdData:SetAsync(plr.UserId, save)
print("saved data")
end)
gui:
Server List:
-
What solutions have you tried so far?
i have tried a bunch of things like jobid but cant figure it out and theres nothing i could find on the fourms