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.
Hi, i think i know why. You did not make a script that detects the gun's bullet. You should make a script so that when the gun's bullet touched the part, the humanoid's health will be reduced. I'll give you guide below.
local GunBullet = -- Please define, this is the gun's bullet local Part = -- Please define, this is the part which humanoid's health will be reduced when hit by the bullet local Humanoid = -- Please define Part.Touched:Connect(function(Touched) if Touched.Parent == GunBullet then Humanoid.Health = 0 disablepower() end end)
PLEASE NOTE: This is just a guide, you need to change a bit of the script :)