How to shorten this code

I have these in a table and want to shorten this, how could I go about doing so?

Code
function Badges.AwardEvent(player, CODE)
	
	local Badge_AWARD = Badges.Badge_AWARD
	local tab = BadgeStorage
	
	if CODE == tab.ReindeerIstiodactylus_ID then
		Badge_AWARD(player, tab.ReindeerIstiodactylus_ID)
	elseif CODE == tab.Elfceras_ID then
		Badge_AWARD(player, tab.Elfceras_ID)
	elseif CODE == tab.SantaOrnithomimus_ID then
		Badge_AWARD(player, tab.SantaOrnithomimus_ID)
	elseif CODE == tab.ChristmasDodo_ID then
		Badge_AWARD(player, tab.ChristmasDodo_ID)
	elseif CODE == tab.SnowmanNothronychus_ID then
		Badge_AWARD(player, tab.SnowmanNothronychus_ID)
	elseif CODE == tab.WendigoTherizinosaurus_ID then
		Badge_AWARD(player, tab.WendigoTherizinosaurus_ID)
	elseif CODE == tab.SnowflakeStegosaurus_ID then
		Badge_AWARD(player, tab.SnowflakeStegosaurus_ID)
	elseif CODE == tab.EarlyWinterFrostSauroposeidon_ID then
		Badge_AWARD(player, tab.EarlyWinterFrostSauroposeidon_ID)
	elseif CODE == tab.WhiteWalkerCarcharodontosaurus_ID then
		Badge_AWARD(player, tab.WhiteWalkerCarcharodontosaurus_ID)
	elseif CODE == tab.PeakSpinosaurus_ID then
		Badge_AWARD(player, tab.PeakSpinosaurus_ID)
	elseif CODE == tab.YetiAlbertosaurus_ID then
		Badge_AWARD(player, tab.YetiAlbertosaurus_ID)
	elseif CODE == tab.SantaClawz_ID then
		Badge_AWARD(player, tab.SantaClawz_ID)
	elseif CODE == tab.Krampus_ID then
		Badge_AWARD(player, tab.Krampus_ID)
	elseif CODE == tab.FaceHuggerRex_CODE then
		Badge_AWARD(player, tab.FaceHuggerRex_ID)
	elseif CODE == tab.DazzlingDacentrurus_CODE then
		Badge_AWARD(player,tab.DazzlingDacentrurus_ID)
	elseif CODE == tab.EvilSantaClawz_CODE then
		Badge_AWARD(player,tab.EvilSantaClawz_ID)
	elseif CODE == tab.BlizzardBalaur_CODE then
		Badge_AWARD(player,tab.BlizzardBalaur_ID)
	elseif CODE == tab.OrionAegisuchus_CODE then
		Badge_AWARD(player,tab.OrionAegisuchus_ID)
	elseif CODE == tab.GlacierAllosaurus_CODE then
		Badge_AWARD(player,tab.GlacierAllosaurus_ID)
	elseif CODE == tab.Xenophysis_CODE then
		Badge_AWARD(player,tab.Xenophysis_ID)
	elseif CODE == tab.DodoChan_CODE then
		Badge_AWARD(player,tab.DodoChan_ID)
	elseif CODE == tab.Doodoo_CODE then
		Badge_AWARD(player,tab.Doodoo_ID)
	elseif CODE == tab.PartyPoppinTorvosaurus_CODE then
		Badge_AWARD(player,tab.PartyPoppinTorvosaurus_ID)
	elseif CODE ~= tab.ReindeerIstiodactylus_ID or tab.Elfceras_ID or tab.SantaOrnithomimus_ID or tab.ChristmasDodo_ID or tab.SnowmanNothronychus_ID or tab.WendigoTherizinosaurus_ID or tab.SnowflakeStegosaurus_ID or tab.EarlyWinterFrostSauroposeidon_ID or tab.WhiteWalkerCarcharodontosaurus_ID or tab.PeakSpinosaurus_ID or tab.YetiAlbertosaurus_ID or tab.SantaClawz_ID or tab.Krampus_ID or tab.FaceHuggerRex_CODE or tab.DazzlingDacentrurus_CODE or tab.EvilSantaClawz_CODE or tab.BlizzardBalaur_CODE or tab.OrionAegisuchus_CODE or tab.GlacierAllosaurus_CODE or tab.Xenophysis_CODE or tab.DodoChan_CODE or tab.Doodoo_CODE or tab.PartyPoppinTorvosaurus_CODE then
		AwardEvent:FireClient(player,"DENIED")
	end
	
end

I’m guessing tab is a Dictionary judging by the way you set stuff up, maybe you can do something like this?

function Badges.AwardEvent(player, CODE)
	
	local Badge_AWARD = Badges.Badge_AWARD
	local tab = BadgeStorage
	
	local awarded = false
	
	for _, Id in pairs(tab) do
		if Id ~= CODE then
			continue
		end
		awarded = true
		Badge_AWARD(player, Id)
	end
	
	if not awarded then
		AwardEvent:FireClient(player,"DENIED")
	end
end
2 Likes