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

Simple explosion not working properly?

Asked by 6 years ago

So I have a Bomb tool that when you click drops a bomb. 5 seconds later it explodes, and anything it touches that isn't in the "unbreakable" folder in the Workspace will be unanchored. It kinda of works. The explosion's position is the original position the bomb was dropped in. I don't know why this happens.

local debounce = true
local plr = nil

script.Parent.Activated:connect(function()
    if debounce then
        debounce = false
        plr = script.Parent
        script.Parent.Handle.Transparency = 1
        script.Parent.top.Transparency = 1
        local clone = game.ReplicatedStorage.bomb:Clone()
            clone.Parent = workspace.Debris
            clone.Position = script.Parent.Handle.Position
        wait(5)
        local explosion = Instance.new("Explosion")
        explosion.BlastPressure = 50000
        explosion.BlastRadius = 10
        explosion.DestroyJointRadiusPercent = 10
        explosion.Parent = clone
        explosion.Position = Vector3.new(clone.Position + Vector3.new(0,2,0))
        explosion.Hit:connect(function(part, distance)
            if part.Parent ~= workspace.unbreakable then
                part.Anchored = false
            end
        end)
        wait(1)
        clone:Destroy()
        wait(5)
        debounce = true
        script.Parent.Handle.Transparency = 0
        script.Parent.top.Transparency = 0
    end
end)

Also, is it possible to make it so anything on top the brick that is unanchored also become unanchored?

Thanks

0
Why clone it? CraytiveWarrior 0 — 6y

1 answer

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
6 years ago

I don't suggest using:

if part.Parent ~= workspace.unbreakable then
part.Anchored = false

As its not needed here instead use the code below and tell me if it works.

local debounce = true
local plr = nil

script.Parent.Activated:connect(function()
    if debounce then
        debounce = false
        plr = script.Parent
        script.Parent.Handle.Transparency = 1
        script.Parent.top.Transparency = 1
        local clone = game.ReplicatedStorage.bomb:Clone()
            clone.Parent = workspace.Debris
            clone.Position = script.Parent.Handle.Position
        wait(5)
        local explosion = Instance.new("Explosion")
        explosion.BlastPressure = 50000
        explosion.BlastRadius = 10
        explosion.DestroyJointRadiusPercent = 10
        explosion.Parent = clone
        explosion.Position = Vector3.new(clone.Position + Vector3.new(0,2,0))
       explosion.Hit:connect(function(part, distance)
            if part.Parent == workspace.unbreakable or part.Parent.Parent == workspace.unbreakable then
                return elseif part.Parent == workspace or part.Parent.Parent == workspace  then
                part.Anchored = false
            end
        end)
        wait(1)
        clone:Destroy()
        wait(5)
        debounce = true
        script.Parent.Handle.Transparency = 0
        script.Parent.top.Transparency = 0
    end
end)


0
That's just my code except longer. It still doesn't fix my problem with the position not being correct MakeYourEscape 334 — 6y
0
Never knew the explosions position was not correct should've at least told us the problem. Prestory 1395 — 6y
Ad

Answer this question