[RESOLVED] Parent Property of "Server" is locked, Current Parent: NULL

I am making a Server List system, it works. But when I create a new one / refresh the GUI, it throws the error in the title.

Extra Info (EDIT): This is happening when I use it after my friend used it.

local ServersFrames = {}
local Update_Gui = function()
	ServersFrames = {}
	table.clear(ServersFrames) -- // Just incase lol
	
	for _, ServerVal in pairs(game:GetService('ReplicatedStorage'):WaitForChild('Servers'):GetChildren()) do
		
		local name = ServerVal.Name
		
		local serverStats = string.split(ServerVal.Value, ' ')
		
		local id = serverStats[1]
		local plrs = serverStats[2]
		
		for i,v in pairs(workspace:WaitForChild('serverboard'):WaitForChild('SurfaceGui'):WaitForChild('ScrollingFrame'):GetChildren()) do
			if v:IsA("Frame") then
				v:Destroy()
			end
		end
		
		local serversFrame = script:WaitForChild('Server'):Clone()
		
		serversFrame:WaitForChild('ServerName').Text = name .. "\n ID: " .. id
		serversFrame:WaitForChild('Playeramount').Text = plrs .. "/" .. game:GetService('Players').MaxPlayers
		
		table.insert(ServersFrames, serversFrame)
		
		serversFrame:WaitForChild('Join').Activated:Connect(function()
			game:GetService('ReplicatedStorage'):FindFirstChild('JoinServer'):FireServer(id)
		end)
		
		for _, serverFrame in pairs(ServersFrames) do
			if serverFrame ~= nil then
				serverFrame.Parent = workspace:WaitForChild('serverboard'):WaitForChild('SurfaceGui'):WaitForChild('ScrollingFrame')
			end
		end
	end
end

workspace:WaitForChild('servercreater'):WaitForChild('SurfaceGui'):WaitForChild('Creater'):WaitForChild('Join').Activated:Connect(function()
	game:GetService('ReplicatedStorage'):WaitForChild('CreatePrivate'):FireServer()
end)

game:GetService('ReplicatedStorage').Servers.ChildAdded:Connect(Update_Gui)
game:GetService('ReplicatedStorage').Servers.ChildRemoved:Connect(Update_Gui)
local serversFrame = script:WaitForChild('Server'):Clone()

Try to give it a parent?

serversFrame.Parent = ~~~
1 Like

I did in the table, I fixed it. I just had to move the for loop

1 Like

Don’t clone the server list as it’s being destroyed, clone it before it’s being destroyed, store it in a variable and parent it when it’s needed.
After that, store a clone of the clone in that original variable where the clone was so you have a new backup.
Let me know if this is confusing

game:GetService(ā€˜ReplicatedStorage’).Servers.ChildRemoved:Connect(Update_Gui)
game:GetService(ā€˜ReplicatedStorage’).Servers.ChildAdded:Connect(Update_Gui)
game:GetService(ā€˜ReplicatedStorage’).Servers.ChildRemoved:Connect(Update_Gui)
game:GetService(ā€˜ReplicatedStorage’).Servers.ChildAdded:Connect(Update_Gui)

Update_Gui()

repeat wait() until workspace:WaitForChild(ā€˜serverboard’):WaitForChild(ā€˜SurfaceGui’):WaitForChild(ā€˜ScrollingFrame’).CanvasSize.Y.Offset > game:GetService(ā€˜Players’).LocalPlayer:WaitForChild(ā€˜PlayerGui’):WaitForChild(ā€˜ServerBoard’):WaitForChild(ā€˜SurfaceGui’).AbsoluteSize.Y

workspace:WaitForChild(ā€˜serverboard’):WaitForChild(ā€˜SurfaceGui’):WaitForChild(ā€˜ScrollingFrame’).CanvasSize = UDim2.new(0, 0, 0, game:GetService(ā€˜Players’).LocalPlayer:WaitForChild(ā€˜PlayerGui’):WaitForChild(ā€˜ServerBoard’):WaitForChild(ā€˜SurfaceGui’).AbsoluteSize.Y)

game:GetService(ā€˜ReplicatedStorage’).Servers.Changed:Connect(Update_Gui)

Update_Gui() – // To initialise the Gui