The point of the script it to activate the battle once a player touches the NPC part. The problem is that upon the NPC's death to end the battle, the battle still continues, ignoring the if statement under the function.
If it helps, here is a gif I created to help you understand the problem. https://gyazo.com/494f8e059ced73cb8c8e2f52f5d03c6b
script.Parent.Anchored = true
script.Parent.CanCollide = false
local CombatActive = false
function CombatInitiate(part)
local human = part.Parent:FindFirstChild("Humanoid" and "Torso")
if human ~= nil then
if CombatActive == false then
CombatActive = true -- Disables function if activated
-- Bad Brick Properties
script.Parent.Anchored = true
script.Parent.CanCollide = false
script.Parent.Position = script.Parent.Parent.Parent.BattleField.EnemyPlatform.Position
print("Combat Simulation Successful")
-- Local Player Properties
part.Parent.Humanoid.WalkSpeed = 25
part.Parent.Torso.CFrame = script.Parent.Parent.Parent.BattleField.PlayerPlatform.CFrame
-- Battle Theme
script.Parent.Parent.Parent.BattleTheme:Play()
elseif CombatActive == true then
return end -- Prevents mutliple battles on the same opponent
end
end
if script.Parent.Parent.Humanoid.Health <= 0 then
script.Parent.Parent.Parent.BattleTheme:Stop()
script.Parent.Position = script.Parent.Parent.Parent.EnemySpawn.Position
wait(5)
CombatActive = false
end
script.Parent.Touched:connect(CombatInitiate)

2 comments
I'm not sure if I'm too inexperienced with humanoids and their properties to understand, but the improved script doesn't call the function upon the humanoid's death when I tested it (I assume the .Died event activates when the humanoid reaches 0 health).
The died event activates when the Humanoid dies.