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

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

Asked by 5 years ago

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.

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? milkdelicious 1 — 5y
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. CodeREVKids 5 — 5y
0
and can you tell to me what error print your output? milkdelicious 1 — 5y
0
More interested in just being able to destroy the wall when the fireball touches it. CodeREVKids 5 — 5y
View all comments (2 more)
0
you should connect the touched event to the fireball instead hellmatic 1523 — 5y
0
I'm not outputting any errors it seems. I should add that the FireBall is a cloned object if that helps. CodeREVKids 5 — 5y

1 answer

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

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.

0
Also, you seriosuly have to indent blockmask 374 — 5y
Ad

Answer this question