I want to make a function that does something when a player receives an item but only if it comes from a certain chest. I'm not sure how to accomplish this in eluna but I came up with this and can someone look at it and tell me what's wrong?

Code:
local function OnOpeningChest(event, player, item, target)
	local ChestName = item:GetName()
	if ChestName == "Chest of Fortune" then
		local function OnLootLegendary(event, player, item, count)
			local quality = item:GetQuality()
			if (quality == 5) then
				local PlayerName = player:GetName()
				local ItemLink = item:GetItemLink()
				SendWorldMessage(PlayerName .. " has unboxed " .. ItemLink .. "!")
			end
		end
	end
end

RegisterItemEvent(2, OnOpeningChest)
RegisterPlayerEvent(32, OnLootLegendary)