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

How to Destroy a specific Part when another Specific part touches it?

Im not a great programmer but have been really into learning how to script in Roblox lately and this site has helped me learn alot over the past few months.

I am trying to Script a wall that blows up when it is touched by a FireBall. So I made the FireBall launcher tool (which shoots spheres named fireballs)

and then I created a wall named DestructibleWall I then attached a script to the DestructibleWall and wrote the following code.

local function OnTouched(hit)

if hit.Name == 'FireBall'

then

Instance.new("Explosion", game.Workspace)

local explosion = Instance.new('Explosion')

game.Workspace.Explosion.Position = script.Parent.Position

script.Parent:Destroy()

end

end

script.Parent.Touched:connect(OnTouched)

Sadly this is not working. Nothing Happens when the FireBalls touch the wall. I should mention that the FireBalls create Explosions when they touch any object. I'm not sure what I'm doing wrong here. Any advice would be very much appreciated.

6 comments

0

wait, why did you put Instance.new("bla bla bla", parent) without a reference, and later you writed the same thing without a parent?

0

Because I would also like to create explosion when the wall is hit though (2 explosions, probably unnecessary). Looks like I failed to make that clear.

0

and can you tell to me what error print your output?

0

More interested in just being able to destroy the wall when the fireball touches it.

0

you should connect the touched event to the fireball instead

0

I'm not outputting any errors it seems. I should add that the FireBall is a cloned object if that helps.

1 answer

Ok, with a quick glance, I already saw what you had wrong. First of all, you made an explosion, and parented it to workspace, and not settings it's position which causes an explosion to spawn at Vector3.new(0,0,0). Third of all, You made an explosion but didn't parent it to anything. Simply do

Explosion.Parent = workspace

That's basically it, no other errors that I see.

1 comment

0

Also, you seriosuly have to indent

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