I just finished making a basic taser tool, the layout out being (Tool>Handle>LocalScript). Anyways, the script runs through fine when I'm testing it out in a test server, but whenever it makes contact with someone who's health is 0, it breaks.
So say for examples, Player1 uses the taser on Player2, and kills him. If Player1 hits one of Player2's limbs before he respawns, Player1's taser breaks and does work anymore until he resets. Here is the script:
debounce = false
script.Parent.Touched:connect(function(part)
if not debounce then
debounce = true
local human = part.Parent:findFirstChild("Humanoid")
local a = part.Parent:GetChildren()
if (human == nil) then return end
if human.Health <= 0 then return end
if part.Parent.Head.face ~= nil then
part.Parent.Head.face:Remove()
end
local d = Instance.new("Decal",part.Parent.Head)
d.Texture = ("http://www.roblox.com/asset/?id=145854465")
d.Face = ("Front")
local s = Instance.new("Sparkles",part.Parent.Torso)
for i=1,5 do
for i,v in pairs(a) do
if v:IsA("Part")then
v.BrickColor = BrickColor.new("Teal")
end
end
wait(0.1)
for i,v in pairs(a) do
if v:IsA("Part")then
v.BrickColor = BrickColor.new("Really black")
end
end
wait(0.1)
end
human.Health = 0
s:Remove()
debounce = false
end
end)

3 comments
Alright, thank you for correcting me, the fix worked and I know what why it broke. Also, when you say tab your code correctly, what do you mean? The tutorials I've been reading/watching haven't explained how to tab your code correctly.
Increase an indent when you start a block -- after
do,then,repeat, etc. Decrease an indent when you end a block -- starting atend,until, etc.Ok thanks.