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

Any reason as to why explosion on touch isn't working?

Hi, i have an explosion script but it doesn't appear to work. It's supposed to explode a part once another part is touched Any ideas? Script:

local lock = 0

script.Parent.Touched:Connect(function(hit)
  local bang = instance.new("Explosion")
  local h = hit.Parent:FindFirstChild("Humanoid")
    bang.BlastPressure = 67
    bang.BlastRadius = 40
    if h ~= nil then
    lock = lock +1
     if not lock == 1 then
       bang.Position = game.Workspace.specialexplosionpart2.Position
             wait(2)
         bang.parent = game.Workspace
       end
    end
end)

2 comments

0

Maybe add the parent first before changing the position?

0

Hmm, seems to just spawn the explosion in a random position. I'm going to try re-installing Roblox Studio. May just be my computer or something like that.

1 answer

✓ Accepted answer

Lock will be always 1, you either have to remove the line where it checks it, or make something for it to not be 1

local lock = 0

script.Parent.Touched:Connect(function(hit)
  local bang = instance.new("Explosion")
  local h = hit.Parent:FindFirstChild("Humanoid")
    bang.BlastPressure = 67
    bang.BlastRadius = 40
    if h ~= nil then
    -- lock = lock +1 was the problem
     if not lock == 1 then
       bang.Position = game.Workspace.specialexplosionpart2.Position
             wait(2)
         bang.parent = game.Workspace
       end
    end
end)

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