Why is this happening??? code:
server
local Servers = game.ReplicatedStorage:WaitForChild("Servers")
local messagingService = game:GetService("MessagingService")
local PossibleNames = {"Bob", "Guy", "Chad", "Bad", "Good", "Mean", "Smart", "Class", "Bart", "Foom", "Panda", "Fox", "Legend"}
function CheckIfServerAlreadyStored(Id)
if #Servers:GetChildren() == 0 then
return {nil, false}
else
for i, v in pairs(game.ReplicatedStorage.Servers:GetChildren()) do
if v.ServerID == Id then
return {v, true}
else
return {nil, false}
end
end
end
end
messagingService:SubscribeAsync("ServerData", function(playersv, regionv, Idv)
if Idv == game.JobId then else
local newServer = Instance.new("Folder")
if CheckIfServerAlreadyStored(Idv)[2] == true then
newServer.Name = CheckIfServerAlreadyStored(Idv)[1]
else
newServer.Name = PossibleNames[math.random(1, #PossibleNames)]
end
newServer.Parent = Servers
local region = Instance.new("StringValue")
local players = Instance.new("NumberValue")
local Id = Instance.new("NumberValue")
players.Value = playersv
Id.Value = Idv
region.Value = "e"
region.Parent = Servers[newServer.Name]
players.Parent = Servers[newServer.Name]
Id.Parent = Servers[newServer.Name]
region.Name = "Region"
players.Name = "Players"
Id.Name = "ServerID"
wait(10)
newServer:Destroy()
end
end)
client
local ServerList = game.ReplicatedStorage:WaitForChild("Servers")
local replicatedStorage = game:GetService("ReplicatedStorage")
local teleportService = game:GetService("TeleportService")
script.Parent.TextButton.MouseButton1Down:Connect(function()
if script.Parent.TextLabelSelectedServer.Text == "Selected Server: None" then
teleportService:Teleport(11755651911, game.Players.LocalPlayer)
else
teleportService:TeleportToPlaceInstance(11755651911, game.ReplicatedStorage.Servers:WaitForChild(script.Parent.TextLabelSelectedServer.Text).ServerID.Value)
end
end)
-- Detect new servers
replicatedStorage.Servers.ChildAdded:Connect(function(newServerAdded_)
local newServerAdded = replicatedStorage:WaitForChild("Template"):Clone()
newServerAdded.Text = "Players: ".. newServerAdded_:WaitForChild("Players").Value .. ", Region: " .. newServerAdded_:WaitForChild("Region").Value .. " Name: " .. newServerAdded_.Name
newServerAdded.Name = newServerAdded_.Name
newServerAdded.Parent = script.Parent.ServerListScrollingGui
end)
script.Parent.ServerListScrollingGui.ChildAdded:Connect(function(child)
child.MouseButton1Down:Connect(function()
script.Parent.TextLabelSelectedServer.Text = child.Name
end)
end)
ServerList.ChildRemoved:Connect(function(child)
if script.Parent.ServerListScrollingGui[child.name] then
script.Parent.ServerListScrollingGui[child.name]:Destroy()
end
end)