I’m making a Private server system for my upcoming roleplay game, but I’m having trouble listing the players owned servers.
Wondering if someone could help me out with this, because I’m confused
Here is the error it gives me:
This is the data saved in the DataStore:
local ServerData = {
Name = PrivateServerName,
JoinCode = PrivateServerJoinCode,
ServerID = ReservedServerID
}
Here’s a part of the Client-Side script:
PrivateServers:WaitForChild("ReturnOwnedServers").OnClientEvent:Connect(function(OwnedServers)
for _, child in pairs(Screens.OwnedServers.Content.ServerList:GetChildren()) do
if child:IsA("TextButton") then
child:Destroy()
end
end
for i, server in pairs(OwnedServers) do
local serverName = server.Name
local joinCode = server.JoinCode
local serverButton = script:WaitForChild("ServerItem"):Clone()
serverButton.ServerName.Text = serverName .." - " .."Join Code: " ..joinCode
serverButton.Parent = Screens.OwnedServers.Content.ServerList
end
end)
Here’s a part of the Server-Side Script:
local function GetOwnedPrivateServers()
local ownedServers = {}
local success, data = pcall(function()
return PrivateServerDataStore:GetAsync(Player.UserId)
end)
if success and data then
ownedServers = data
ReplicatedStorage:WaitForChild("PrivateServers"):WaitForChild("ReturnOwnedServers"):FireClient(Player, ownedServers)
else
print("Failed to retrieve owned servers.")
ReplicatedStorage:WaitForChild("PrivateServers"):WaitForChild("ReturnOwnedServers"):FireClient(Player, {})
end
end
ReplicatedStorage:WaitForChild("PrivateServers"):WaitForChild("GetOwnedServers").OnServerEvent:Connect(function(Player)
GetOwnedPrivateServers()
end)