--Creates a server-side buffer. Inherits the base buffer class.

function BufferCreator:CreateServerBuffer(BufferName)
	local BufferFolder = Instance.new("Folder")
	BufferFolder.Name = BufferName
	BufferFolder.Parent = Tool
	
	local Buffer = CreateBuffer(BufferFolder)
	local Player
	
	--Adds an item to the buffer.
	function Buffer:AddItem(NewItem)
		NewItem.Parent = BufferFolder
		
		local Part = (NewItem:IsA("BasePart") and NewItem) or NewItem:FindFirstChildWhichIsA("BasePart",true)
		if Part then
			--Add a position lock.
			local HoldPos = Vector3.new(math.random(-1000,1000),100000,math.random(-1000,1000))
			Part.CFrame = CFrame.new(HoldPos)
			local PositionLock = Instance.new("BodyPosition")
			PositionLock.Position = HoldPos
			PositionLock.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			PositionLock.Name = "BufferPositionLock"
			PositionLock.Parent = Part
			
			--Set the network ownership to the client so it can control physics.
			if Part:IsDescendantOf(game.Workspace) and not Part.Anchored and Player then
				Part:SetNetworkOwner(Player)
			end
		end
	end
	
	--Sets the network ownership of the buffer.
	function Buffer:SetCurrentPlayer(NewPlayer)
		Player = NewPlayer
		
		for _,Item in pairs(BufferFolder:GetChildren()) do
			local Part = (Item:IsA("BasePart") and Item) or Item:FindFirstChildWhichIsA("BasePart",true)
			
			if Part and Part:IsDescendantOf(game.Workspace) and not Part.Anchored and Player then
				Part:SetNetworkOwner(NewPlayer)
			end
		end
	end
	
	--Return the buffer class.
	return Buffer
end
