I have a script that creates two Instance.new parts named "Zap" and "Zap2". These two will destroy themselves immediately if they hit another player but if they don't then they are supposed to just be destroyed five seconds later. I was able to manage to get the first Zap to destroy on it's own after five seconds, but the second one won't destroy on it's own it will just wait for it to come in contact with another player. This is really confusing me so please help.
Zap.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid == nil then return end
if AlreadyTouched == false then
AlreadyTouched = true
if Humanoid.Parent == Character then
AlreadyTouched = false
print("Local Humanoid Touched")
Humanoid.Health = Humanoid.Health - 0
else
if deb == true then return end
deb = true
print("Humanoid Touched")
Humanoid.Health = Humanoid.Health - 30
Zap:Destroy() --Works
end
wait(5)
deb = false
Zap:Destroy() --Works
end
end)
Zap2.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid == nil then return end
if AlreadyTouched2 == false then
AlreadyTouched2 = true
if Humanoid.Parent == Character then
AlreadyTouched2 = false
print("Local Humanoid Touched")
Humanoid.Health = Humanoid.Health - 0
else
if deb2 == true then return end
deb2 = true
print("Humanoid Touched")
Humanoid.Health = Humanoid.Health - 30
Zap2:Destroy() --Works
end
wait(5)
deb2 = false
Zap2:Destroy() --Doesn't Work
end
end)
wait(0.2)
Debounce = false
end)

4 comments
I have set up values for the "AlreadyTouched2" and "deb2" I'm not just making them out of the blue.
Where is the instances being created?
In an earlier part in the same script.
I just didn't want to post the full script all at once because then it would just get overwhelming