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

Simple explosion not working properly?

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

1 comment

0

Why clone it?

1 answer

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)


2 comments

0

That's just my code except longer. It still doesn't fix my problem with the position not being correct

0

Never knew the explosions position was not correct should've at least told us the problem.

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