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

Exploding barrels don't work, why not? [closed]

Asked by
1Juice1 10
10 years ago

In my game, when you shoot a barrel, there will be an explosion and small bricks will splatter around, then the barrel will explode, however, it's not working. What am I doing wrong in the script? Do I need a special function for hit or something?

function onTouched(hit)
    if hit.Name == "Bullet" then
        local explosion = Instance.new("Explosion", script.Parent)
        local maxDamage = 50
        explosion.BlastPressure = 0
        explosion.BlastRadius = 8
        explosion.Hit:connect(function(hitPart, partDistance)
            local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
            if humanoid then
                local distance_factor = partDistance/explosion.BlastRadius
                distance_factor = 1 - distance_factor
                humanoid:TakeDamage(maxDamage*distance_factor)
            end
        end)
        for i = 1,8 do
            local debris = Instance.new("Part", game.Workspace)
            debris.FormFactor = "custom"
            debris.BrickColor = BrickColor.new("Black")
            debris.Size = Vector3.new(0.6, 0.6, 0.6)
        end
        script.Parent:Destroy()
    end
end

script.Parent.Touched:connect(onTouched)

Locked by adark and TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

Line 17 -- > "Custom"

Ad