Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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)
0
Maybe add the parent first before changing the position? Antelear 185 — 2y
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. Mrpolarbear2games 55 — 2y

1 answer

Log in to vote
1
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

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

Answer this question