The OnEntityCreated function does not correctly handle the case when called from an on_entity_cloned event, in which case it will always early return as the entity variable will be nil every time.
This is due to the event having a different structure.
The entity assignment line would have to change to this:
local entity = event.created_entity or event.entity or event.destination
to correctly handle the event.