Private Server Help

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)
2 Likes

here see if this helps on 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)
2 Likes

Doesn’t give me any errors in the console either

Perfect! If it showing “nil” is not what you want, maybe try and find out why they are returning nil. Unfortunately, I can’t provide any more help. Best of luck! :slight_smile:

Alright, Thank you so much for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.