How to detect a Model is nil/destroyed/goneFromServer?

attacks = PlayersAttackSelect()
	for i,v in pairs (attacks) do
		if v.Target.BattleInfo.Alive.Value == false then v.Target = Enemies[math.random(1,#Enemies)] end -- This line
		PlayerAttacks(v.Attacker,v.Attack,v.Target,PlrsChar,Stage)
		for i,v in pairs (Enemies) do
			if Enemies[i].BattleInfo.Alive.Value == false then 
				Enemies[i]:Destroy()
				table.remove(Enemies,i)	
			end
		end
		if next(Enemies) == nil then BattleActive = false end
	end

If the Target dies, then it’s model get destroyed, but when other players are trying to attack the same target, he’s not there (and thus the script stops). I need a way to detect that the Target Model is not there anymore so the game selects a new target.

Edit: I’ll just take the complicated path.

1 Like

FindFirstChild is great to use in these situations because instead of erroring, it’ll just return nil if the Instance doesn’t exist.

1 Like

Or you could say “if target then”

1 Like

if no v.Target then Doesn’t scan if the enemy is alive and thus no select random enemy, breaking the script.
if v.Target then Game goes wild and selects new enemy, despite the target is alive.

1 Like

if no v.Target.Parent:FindFirstChild(v.Target) Doesn’t work. It still breaks the script.

The opposite (by removing not) breaks the script too.

1 Like