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 7 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.

local meteor = Instance.new('Part', game.Workspace)
meteor.Name = 'Meteor'
meteor.Anchored = false


meteor.Touched:connect(function(boom)
    if boom.Name ~= 'Baseplate' and boom ~= nil then 
        local boom = Instance.new('Explosion', game.Workspace)
        boom.Position = boom.Position
        boom:Destroy()
    end
end)

1 answer

Log in to vote
0
Answered by 7 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,

local meteor = Instance.new('Part', game.Workspace)
meteor.Name = 'Meteor'
meteor.Anchored = false

meteor.Touched:connect(function(part)
    if part.Name ~= 'Baseplate' then 
        local boom = Instance.new('Explosion', game.Workspace)
        boom.Position = part.Position
        part:Destroy()
    end
end)
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