I am making a system where an electric fence is powered by a power box nearby. The goal is that when you shoot the power box, the power goes down and the electric fence is safe to climb. However, when you shoot the box, nothing happens and there are no errors. This is the script:
function disablepower()
script.Parent.Parent.Parent.ElectricFenceMain.KillPart:Destroy() --This stops the player from dying
script.Parent.ParticleEmitter.Enabled = true --This adds a cool little electricity effect
script.Parent.Parent.zap:Play() --This plays an electricity sound
print("Fence power down!") -- Lets me know if its worked (when testing)
wait(2)
script.Parent.ParticleEmitter.Enabled = false
script.Disabled = true --This stops the whole process from happening again (even though it shoudn't anyway)
end
script.Parent.Parent.Humanoid.Died:Connect(disablepower)
The script works by checking to see if the humanoid has died. It's a model with one part so basically if you shoot the part, it will take health from the humanoid. Once the part has been shot, it will die and the script should work. The gun does 100 damage and the part has 100 health so it should be insta-kill. I've even lowered the health of the power box but still nothing happens.
I've tried so many things but I can't figure it out. Any help is appreciated.

3 comments
Can't you do game.Workspace.ElectricFenceMain.KillPart:Destroy()
Try naming script.Parent "Head"
I cant do game.Workspace etc because I am building a map that will be moved later but these will all be in the same trajectory. Also, i already named it Head