Help with error = attempt to index a nil value

I'm having a time of it trying to work out why I keep getting the error :
[lua] [string "COORDINATED_BARRAGE_153151_TITLE (RESOLUTION_TIME_ACTION)~0x000005ea"]:2: attempt to index a nil value
on the following card I made for Coordinated Barrage.
I used Sumomole's Adaptive Automaton and code for the base and the card seems to work just fine. I keep getting this error when I quit though and I keep trying to fix it but I think I have been looking at code too long the past few weeks and I have no idea what to do to get rid of the error.
Here is the code :

[lua] [string "COORDINATED_BARRAGE_153151_TITLE (RESOLUTION_TIME_ACTION)~0x000005ea"]:2: attempt to index a nil value
on the following card I made for Coordinated Barrage.
I used Sumomole's Adaptive Automaton and code for the base and the card seems to work just fine. I keep getting this error when I quit though and I keep trying to fix it but I think I have been looking at code too long the past few weeks and I have no idea what to do to get rid of the error.
Here is the code :
- Code: Select all
<SPELL_ABILITY>
<SFX text="TARGET_PIERCE_PLAY" />
<TARGET tag="CARD_QUERY_CHOOSE_CREATURE_DEAL_DAMAGE" definition="0" compartment="0" count="1" />
<TARGET_DEFINITION id="0">
local filter = ClearFilter()
filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
local subFilter = filter:AddSubFilter_Or()
subFilter:Add(FE_IS_ATTACKING, true)
subFilter:Add(FE_IS_BLOCKING, true)
</TARGET_DEFINITION>
<RESOLUTION_TIME_ACTION>
local zone = ZONE_ANYWHERE
local player = EffectController()
S_CountCreatureTypes(zone, player)
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION repeating="1">
local player = EffectController()
return S_ChooseCreatureType(player)
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
LinkedDC():Set_Int(0, S_ChosenCreatureType())
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local target_creature = EffectDC():Get_Targets(0):Get_CardPtr(0)
if ( target_creature ~= nil ) then
local filter = ClearFilter()
filter:Add( FE_SUBTYPE, OP_IS, S_ChosenCreatureType() )
filter:Add( FE_CONTROLLER, OP_IS, EffectController() )
local damage = filter:Count()
EffectSourceLKI():DealDamageTo( damage, target_creature )
end
</RESOLUTION_TIME_ACTION>
<AI_SIMPLIFIED_TARGETING compartment="0" hint="HINT_ENEMY_ONLY" />
</SPELL_ABILITY>
