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

Trying to make a brick explode when it touches the object. Help?

I'm trying to make vehicle when it like gets flipped over, it explodes and the parts along it are caught on fire. So far I made brick and put it on top of the vehicle; however, it explodes when a player touches the brick. How do I make so that it blows up when it touches the ground or the object rather than a humanoid player? Here's my script;

wait (1)
function boom()
script.Parent.Anchored = true
script.Parent.Parent.Gun1.Anchored = true
script.Parent.Parent.Gun2.Anchored = true
script.Parent.Parent.Engine.Anchored = true
wait (0.01)
a = Instance.new ("Explosion")
a.Parent = Workspace
a.Position = script.Parent.Position
a.BlastRadius = 10
wait (1)
script.Parent.Anchored = false
script.Parent.Parent.Gun1.Anchored = false
script.Parent.Parent.Gun2.Anchored = false
script.Parent.Parent.Engine.Anchored = false
b = Instance.new ("Fire")
b.Parent = script.Parent
b.Size = 10
c = Instance.new ("Fire")
c.Parent = script.Parent.Parent.Gun1
c.Size = 10
d = Instance.new ("Fire")
d.Parent = script.Parent.Parent.Gun2
d.Size = 10
e = Instance.new ("Fire")
e.Parent = script.Parent.Parent.Engine
e.Size = 10
wait (0.1)
script:remove()
end

script.Parent.Touched:connect (boom)

1 comment

0

just add sn if statement

1 answer

Your problem is that it executes the code whenever the brick touches anything. All you need is a simple if statement that checks if the part that touched is a part of a player. This should help you:

wait (1)
function boom()
	if part.Parent:findFirstChild("Humanoid") ~= nil then
		return nil
	else
		script.Parent.Anchored = true
		script.Parent.Parent.Gun1.Anchored = true
		script.Parent.Parent.Gun2.Anchored = true
		script.Parent.Parent.Engine.Anchored = true
		wait (0.01)
		a = Instance.new ("Explosion")
		a.Parent = Workspace
		a.Position = script.Parent.Position
		a.BlastRadius = 10
		wait (1)
		script.Parent.Anchored = false
		script.Parent.Parent.Gun1.Anchored = false
		script.Parent.Parent.Gun2.Anchored = false
		script.Parent.Parent.Engine.Anchored = false
		b = Instance.new ("Fire")
		b.Parent = script.Parent
		b.Size = 10
		c = Instance.new ("Fire")
		c.Parent = script.Parent.Parent.Gun1
		c.Size = 10
		d = Instance.new ("Fire")
		d.Parent = script.Parent.Parent.Gun2
		d.Size = 10
		e = Instance.new ("Fire")
		e.Parent = script.Parent.Parent.Engine
		e.Size = 10
		wait (0.1)
		script:remove()
	end
end

script.Parent.Touched:connect(boom)

Accept if this helped

2 comments

0

Now it just doesn't explode at all.

0

ok try now. but i have no idea why it didn't work before. maybe you misspelled something?

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