Using SetNWString

I have written this (shared):


-- Door Functions
local meta = FindMetaTable("Entity")

-- Ownership Type
function meta:SetOwnershipType(OwnershipType)
	if(self.Entity:IsValid()) then
		self:SetNetworkedString("OwnershipType", OwnershipType)
	end
	return false
end

function meta:GetOwnershipType()
	if(self.Entity:IsValid()) then
		if(self:GetNetworkedString("OwnershipType") != nil) then
			return self:GetNetworkedString("OwnershipType")
		else
			self:SetNetworkedString("OwnershipType", "ownable")
			return self:GetNetworkedString("OwnershipType")
		end
	end
	return nil
end

in a server side file I have:


local AllDoors = ents.FindByClass("*door*")
for k,v in pairs(AllDoors) do
	v:SetOwnershipType("ownable")
	v:SetNetworkedString("OwningPlayers", glon.encode({}))
	v:SetNetworkedString("AllowedGroups", glon.encode({}))
end

Yet inside:


function BuyDoor(Player, Command, Arguments)
	local EyeTrace = Player:GetEyeTrace()
	local TraceEntity = EyeTrace.Entity;
	if(TraceEntity:IsValid() and TraceEntity:GetPos():Distance(Player:GetShootPos()) < 400) then
		if(string.find(TraceEntity:GetClass(), "door") != nil) then
			if(table.getn(TraceEntity:GetOwningPlayers()) == 0) then
				if(TraceEntity:CanOwn()) then
					TraceEntity:AddOwner(Player:SteamID())
				else
					Player:ChatPrint("[RR] You cannot buy this door.")
				end
			else
				Player:ChatPrint("[RR] This door is already owned.")
			end
		end
	end
end
concommand.Add("srp_buydoor", BuyDoor)

The TraceEntity:CanOwn() function returns false.