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

Part that destroys other parts script isn't working, help?

Asked by 8 years ago

This is the script i used to make the part, Meteor, fall and when it hits other parts it makes those parts get destroyed from the game. Though it doesn't work and i can't figure out why not.

01local meteor = Instance.new('Part', game.Workspace)
02meteor.Name = 'Meteor'
03meteor.Anchored = false
04 
05 
06meteor.Touched:connect(function(boom)
07    if boom.Name ~= 'Baseplate' and boom ~= nil then
08        local boom = Instance.new('Explosion', game.Workspace)
09        boom.Position = boom.Position
10        boom:Destroy()
11    end
12end)

1 answer

Log in to vote
0
Answered by 8 years ago

You're mixing up the variables.

On line 6 of your script, you'll notice you create a variable named boom. This variable points to what the part, "meteor", touched. On line 8 of your script however, you create another variable named boom again.

How do I fix this?

You don't have to delete an explosion, it does it for you. If you want to delete the part the meteor touched, rename the variable boom, the first boom, to something else.

Example,

01local meteor = Instance.new('Part', game.Workspace)
02meteor.Name = 'Meteor'
03meteor.Anchored = false
04 
05meteor.Touched:connect(function(part)
06    if part.Name ~= 'Baseplate' then
07        local boom = Instance.new('Explosion', game.Workspace)
08        boom.Position = part.Position
09        part:Destroy()
10    end
11end)
I also removed the part where you checked if boom exists, because it will always exist.

Good Luck!

if I helped, please don't forget to accept my answer.
Ad

Answer this question