Help with ents.GetAll()

Im making a script that should make it possible to own doors.
On startup the script is checking for all doors on the map, but it wont work…

Doors = {}
function CheckForDoors()

    for k, v in pairs(ents.GetAll()) do
        if string.find(v:GetClass(),"door") then
        DoorID = v:EntIndex()
        local Door = {id = DoorID, owner = "none" }
        table.insert(Doors, Door)
        print(DoorID)
        end
    end

end

Help please

Place your code in a **[Gamemode.InitPostEntity

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.InitPostEntity)** hook. Your code ran before there were any doors on the map.

oh thanks