Setting spawn limit on an entity

Ok this is what i have but its giving me a serverside error on spawn attempt at: ent:SetPlayer(pl) line
attempt to call method ‘SetPlayer’ (a nil value)
if anyone can fix this thank you.

CreateConVar('sbox_maxmedias', 1)

local function MakeMedia(pl, Data)
	if !pl:CheckLimit("medias") then return nil end
	local ent = ents.Create("Media")
		if !ent:IsValid() then return end
		duplicator.DoGeneric(ent, Data)
	ent:SetName("Streaming Music Player")
	ent.Damaged = false;
	self.On = false;
	self.Play = false;
	duplicator.DoGenericPhysics(ent, pl, Data)
	pl:AddCount("medias", ent)
	pl:AddCleanup("medias", ent)
	return ent
duplicator.RegisterEntityClass("Media", MakeMedia, "Data")

function ENT:SpawnFunction( pl, tr )
	if ( !tr.Hit ) then return end
	local SpawnPos = tr.HitPos + tr.HitNormal * 45
	local ent = MakeMedia( pl, {Pos = SpawnPos} )
	return ent

From what i gather reading the wiki it seems SetPlayer is used for adding items to the players undo list. What were you trying to use it for?

i fixed it already , it was me and lack of sleep but i found it…thanks though