Hello! It’s my first time using the forum.
I’m not a smart scripter, so I need help. I have “PlayerCount” not working correctly for private servers. It constantly stays at “0/50” even if the player teleported to private server.
And there are a couple more clarifications to make it clearer:
- “psid” or “placeid” is an identifier for my second place, including for private servers.
- the Place from which the player is teleported to the further any server, single place. Only 1 player can be in this starter place.
I have attached only part of the code where the resources and sortPrivateServer function are directly specified, where “PlayerCount.Text” is located. The code itself is quite large, 250+ lines.
Part of the code:
-- Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local dataStoreService = game:GetService("DataStoreService")
local teleportService = game:GetService("TeleportService")
local players = game:GetService("Players")
local chat = game:GetService("Chat")
-- DataStores
local dataStores = {
serverAccessCodesDS = dataStoreService:GetDataStore("ServerAccessCodesDS."),
serverNamesDS = dataStoreService:GetDataStore("ServerNamesDS."),
localOwnedServersDS = dataStoreService:GetDataStore("LocalOwnedServersDS."),
customServerJoinCodesDS = dataStoreService:GetDataStore("CustomServerJoinCodesDS."),
globalPrivateServerDS = dataStoreService:GetOrderedDataStore("GlobalPrivateServerDS."),
privateServerOwnerIdDS = dataStoreService:GetDataStore("PrivateServerOwnerIdDS."),
serverInfoDS = dataStoreService:GetDataStore("ServerInfoDS.")
}
-- Paths
local menu = script.Parent.Parent
local create = menu.Log.Create.Create
local join = menu.Log.Join.Join
local owned = menu.Owned
-- Variables
local mouseClick = game.SoundService.MouseClick
local plr = menu.Parent.Parent.Parent.Parent
local placeid = 16814500703
local psid = tostring(placeid)
local server = {}
local serverCodeEntered
local servers = script.Parent.Parent.Parent.Servers
local loading = script.Parent.Parent.Parent.Loading
-- Loader
pcall(function()
for _, v in pairs(dataStores.localOwnedServersDS:GetAsync(plr.UserId) or {}) do
table.insert(server, v)
end
end)
-- Functions
local function generateServerCode()
while true do
local code = math.random(111111, 999999)
if not dataStores.serverNamesDS:GetAsync(code) then
return code
end
end
end
local function sortPrivateServer()
for _, v in pairs(menu.Log.Servers:GetChildren()) do
if v.Name == "PrivateTemp" or v:IsA("UIListLayout") then
v:Destroy()
end
end
local pages = dataStores.globalPrivateServerDS:GetSortedAsync(false, 100)
local data = pages:GetCurrentPage()
for _, v in pairs(data) do
local serverInfoDictionary = dataStores.serverInfoDS:GetAsync(v.key)
if serverInfoDictionary then
local listLayout = replicatedStorage.UIListLayout:Clone()
local privateTemp = replicatedStorage.PrivateTemp:Clone()
listLayout.Parent = menu.Log.Servers
privateTemp.Parent = menu.Log.Servers
privateTemp.ServerName.Text = serverInfoDictionary.ServerName
privateTemp.PlayerCount.Text = (dataStores.globalPrivateServerDS:GetAsync(v.key) or 0).. "/50"
privateTemp.Join.MouseButton1Click:Connect(function()
mouseClick:Play()
menu.Log.Join.Visible = not menu.Log.Join.Visible
menu.Log.Servers.Visible = not menu.Log.Servers.Visible
end)
end
end
end
if string.len(psid) >= 10 then
replicatedStorage.Owner.Value = dataStores.privateServerOwnerIdDS:GetAsync(psid)
end
local function updatePrivateServer()
for _, v in pairs(menu.Log.Owned:GetChildren()) do
if v.Name == "PrivateTemp" or v:IsA("UIListLayout") then
v:Destroy()
end
end
for _, v in pairs(server) do
local id = dataStores.serverNamesDS:GetAsync(v)
local serverInfoDictionary = dataStores.serverInfoDS:GetAsync(id)
local listLayout = replicatedStorage.UIListLayout:Clone()
local privateTemp = replicatedStorage.PrivateTemp:Clone()
listLayout.Parent = menu.Log.Owned
privateTemp.Name = v.._
privateTemp.Parent = menu.Log.Owned
privateTemp.ServerCode.Text = v
privateTemp.ServerName.Text = serverInfoDictionary.ServerName
privateTemp.Join.MouseButton1Click:Connect(function()
mouseClick:Play()
slidingFrame(loading)
loading.Animation.Enabled = true
local code = dataStores.serverAccessCodesDS:GetAsync(id)
teleportService:TeleportToPrivateServer(psid, code, {plr})
end)
end
end