Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

0

Can't you do game.Workspace.ElectricFenceMain.KillPart:Destroy()

0

Try naming script.Parent "Head"

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

1 answer

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

15 comments

0

It doesn't work, still nothing happens. No errors either

0

may i know what is script.Parent.Parent? and what type of script you are using, where is it located etc

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

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?

0

serverscript

0

i keep trying that script but nothing works

0

dude, that script is a guide

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

0

i tried to use it but everytime i tried defining it it just wouldbt work

0

i defined them as: local GunBullet = game.Workspace:WaitForChild("Bullet") local Part = script.Parent local Humanoid = script.Parent.Parent.Humanoid

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

0

sorry, i found another error, u can test again. Btw pls send me errors if u have thanks

0

ok no worries, i will try it again

0

didn't work, but i ended up finding an alternative and worked that way. Thanks anyway

0

well..sorry it didn't help. anyway, thanks for trying. Also, may i know how you make it work?

This discussion is preserved as it was. New answers, comments, and votes are closed.