This is my current code.
It explodes 56 times instead of one, which causes lag for the game.
wait(1)
local folder = workspace.MineFolder
while true do
wait(1)
for _,v in pairs(folder:GetChildren()) do
if v:IsA('BasePart') then
v.Touched:Connect(function(touched)
local possibleHumanoid = touched.Parent:FindFirstChildWhichIsA('Humanoid')
if possibleHumanoid then
possibleHumanoid.Health = 0
v.Transparency = 0
local explosion = Instance.new("Explosion", v)
explosion.Position = v.Position
explosion.BlastRadius = 2
explosion.BlastPressure = 35
print("EXPLOSION!")
end
end)
end
end
end
You want it to explode once (if it detects a humanoid), right? If so, you can just disconnect the .Touched() connection.
wait(1)
local folder = workspace.MineFolder
while true do
wait(1)
for _,v in pairs(folder:GetChildren()) do
if v:IsA('BasePart') then
v.Touched:Connect(function(touched)
local possibleHumanoid = touched.Parent:FindFirstChildWhichIsA('Humanoid')
if possibleHumanoid then
possibleHumanoid.Health = 0
v.Transparency = 0
local explosion = Instance.new("Explosion", v)
explosion.Position = v.Position
explosion.BlastRadius = 2
explosion.BlastPressure = 35
print("EXPLOSION!")
end
end)
end
end
end
local debounce = true
script.Parent.Touched:Connect(function()
if debounce == true then
debounce = false
-- explosions and stuff --
-- if you want to re-enable it --
debounce = true
end
This didnt work either, it still made 56 explosions.
wait(1)
local folder = workspace.MineFolder
local debounce = true
while true do
wait(1)
for _,v in pairs(folder:GetChildren()) do
if v:IsA('BasePart') then
v.Touched:Connect(function(touched)
if debounce == true then
debounce = false
local possibleHumanoid = touched.Parent:FindFirstChildWhichIsA('Humanoid')
if possibleHumanoid then
possibleHumanoid.Health = 0
v.Transparency = 0
local explosion = Instance.new("Explosion", v)
explosion.Position = v.Position
explosion.BlastRadius = 2
explosion.BlastPressure = 35
print("EXPLOSION!")
end
debounce = true
end
end)
end
end
end