Hello all, I'm currently working out a bug with a unique ability I'm programming for one of my Civs. Basically I've programmed an ability where they earn Science from killing enemy units, and the code works flawlessly, except with one key quirk: whenever the player or AI is not currently researching a technology and they trigger the ability, the game will crash. So what I need is to program a tag or something that tells the game when a player is not currently researching anything, to instead take the science yield that the player would receive and store it in memory until they actually do trigger the ability while they are researching. Here's the current state of my attempt to create a solution: Code: function ScienceOnKill(iKiller, iKilled, iUnitType) local pPlayer = Players[iKiller] local iCombatValue = GameInfo.Units[iUnitType].Combat if pPlayer:GetCivilizationType() == iUniqueCiv then if iCombatValue and iCombatValue > 0 then iScienceYield = (math.ceil(iCombatValue * iKillValueYieldMod)); local currentResearch = pPlayer:GetCurrentResearch(); local researchCost = pPlayer:GetResearchCost(); local researchProgress = pPlayer:GetResearchProgress(); if currentResearch then if researchCost > researchProgress then print("Can add Science to Research Progress"); local teamTechs = Teams[pPlayer:GetTeam()]:GetTeamTechs(); iScienceYield = iScienceYield + iCarryOverYield; if (researchProgress + iScienceYield) > researchCost then researchProgress = researchCost; iCarryOverYield = 0; else teamTechs:ChangeResearchProgress(currentResearch, iScienceYield, pPlayer); iCarryOverYield = 0; end else iCarryOverYield = iCarryOverYield + iScienceYield; return; end else iCarryOverYield = iCarryOverYield + iScienceYield; return; end end end end GameEvents.UnitKilledInCombat.Add(ScienceOnKill) So, there's my current situation (I know some of what I've programmed may be redundant, I'm just trying to find a solution that works). Any thoughts? -EDIT- Found a solution (it's a bit cumbersome and rigid, but it works). No more crashes as of right now.