Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My events for checking a humanoid death isn't working?

Asked by 4 years ago

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.

0
Can't you do game.Workspace.ElectricFenceMain.KillPart:Destroy() Geobloxia 251 — 4y
0
Try naming script.Parent "Head" Geobloxia 251 — 4y
0
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 iiPizzaCraver 71 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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 :)

0
It doesn't work, still nothing happens. No errors either iiPizzaCraver 71 — 4y
0
may i know what is script.Parent.Parent? and what type of script you are using, where is it located etc guest_20I8 266 — 4y
0
The model contains a humanoid and the zap sound and a part, the script is inside the part and so is the particle emitter. It is a basic script iiPizzaCraver 71 — 4y
0
Alright, i gave you a guide and explained briefly why your script doesn't work. Btw, what i mean is, if your script a LocalScript or ServerScript? guest_20I8 266 — 4y
View all comments (11 more)
0
serverscript iiPizzaCraver 71 — 4y
0
i keep trying that script but nothing works iiPizzaCraver 71 — 4y
0
dude, that script is a guide guest_20I8 266 — 4y
0
i tried to use it but everytime i tried defining it it just wouldbt work iiPizzaCraver 71 — 4y
0
alright, i've changed the script a bit as i notice a mistake but please add in some stuff as this is just a guide guest_20I8 266 — 4y
0
i defined them as: local GunBullet = game.Workspace:WaitForChild("Bullet") local Part = script.Parent local Humanoid = script.Parent.Parent.Humanoid iiPizzaCraver 71 — 4y
0
is there any errors when u try the script? or rather do u have any errors for ur initial script? If have please send it to me thanks guest_20I8 266 — 4y
0
sorry, i found another error, u can test again. Btw pls send me errors if u have thanks guest_20I8 266 — 4y
0
ok no worries, i will try it again iiPizzaCraver 71 — 4y
0
didn't work, but i ended up finding an alternative and worked that way. Thanks anyway iiPizzaCraver 71 — 4y
0
well..sorry it didn't help. anyway, thanks for trying. Also, may i know how you make it work? guest_20I8 266 — 4y
Ad

Answer this question