Spawning and Exploding Problem

The main problem is that when the bindable event fires, both the explosion and the spawning of the 11 mobs happens more than once.

Here’s the code, if I can figure out where to place the debounce on this script I’ll be set.

for _, parts in pairs(car:GetDescendants())  do
    if debounce then return end
    if parts:IsA("BasePart") then
        parts.Touched:Connect(function(hit)
            if hit == Boulder then
              local explosion = Instance.new("Explosion")
                if Hitbox then 
                    remoteevent:Fire()
                    explosion.Position = Hitbox.Position
                    explosion.Parent = workspace 
                    explosion.ExplosionType = Enum.ExplosionType.Craters
                    explosion.BlastRadius = 20 
                    explosion.BlastPressure = 70
                    parts.Anchored = false 
                    debounce = true 
                    wait(10) 
                    debounce = false
                 parts:BreakJoints() 
               end       
           end
        end)
    end
end

Many thanks.

You need this line to be inside the function(hit) … end function. Where it is right now, it does nothing because it’s presumably initialized to false and you’re only ever checking it when hooking up the event handler functions, rather than when the hit function gets called. As is, you’ll get 1 explosion for every part the boulder hits. Nothing’s actually checking the ‘debounce’ cooldown flag when things are actually colliding.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.