-- folders

local powerupsFolder = replicatedStorage.Game.Powerups
local mapActivePowerupsFolder = game.ReplicatedStorage.MapSettings.Powerups



local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine)

local descendants = maxAmmoFrame:GetDescendants()
local instanceInfoTables = {}

for _, item in pairs (descendants) do
	local infoTable = nil 
	if item:IsA("ImageLabel") then
		infoTable = {INSTANCE = item, PROPERTY = "ImageTransparency", OFF = {ImageTransparency = 1}, ORIGINAL = {ImageTransparency = item["ImageTransparency"]}}
	elseif item:IsA("Frame") then
		infoTable = {INSTANCE = item, PROPERTY = "BackgroundTransparency", OFF = {BackgroundTransparency = 1}, ORIGINAL = {BackgroundTransparency = item["BackgroundTransparency"]}}
	elseif item:IsA("TextLabel") then
		infoTable = {INSTANCE = item, PROPERTY = "TextTransparency", OFF = {TextTransparency = 1}, ORIGINAL = {TextTransparency = item["TextTransparency"]}}
	else
		continue
	end
	table.insert(instanceInfoTables, infoTable)
end
table.insert(instanceInfoTables, {INSTANCE = maxAmmoFrame, PROPERTY = "ImageTransparency", OFF = {ImageTransparency = 1}, ORIGINAL = {ImageTransparency = maxAmmoFrame["ImageTransparency"]}})

local VisibleTime = 4
local Queue = 0
local function updateCard()
	Queue += 1
	maxAmmoFrame.Visible = true

	-- off
	for _, infoTable in pairs (instanceInfoTables) do
		local instance = infoTable["INSTANCE"]
		local property = infoTable["PROPERTY"]
		instance[property] = 1
	end

	-- on
	for _, infoTable in pairs (instanceInfoTables) do
		local instance = infoTable["INSTANCE"]
		local original = infoTable["ORIGINAL"]
		tweenService:Create(instance, tweenInfo, original):Play()
	end

	local start = tick()
	repeat wait() until (tick() - start) > VisibleTime or Queue > 1
	if Queue > 1 then Queue -= 1 return end

	-- off
	for _, infoTable in pairs (instanceInfoTables) do
		local instance = infoTable["INSTANCE"]
		local off = infoTable["OFF"]
		tweenService:Create(instance, tweenInfo, off):Play()
	end

	local start = tick()
	repeat wait() until (tick() - start) > 1 or Queue > 1
	if Queue > 1 then Queue -= 1 return end

	maxAmmoFrame.Visible = false
	Queue -= 1
end

local function powerUpAdded(powerUp)
	if powerUp.Name == "MaxAmmo" then
		updateCard()
	end
end
mapActivePowerupsFolder.ChildAdded:Connect(powerUpAdded)


