I have a bomb that makes everything in a certain proximity turn to Corroded Metal. When that happens, I'd like it to unanchored once it turns that material. Also, delete itself after a period of time.
1 | if Parent.Material = "CorrodedMetal" |
2 | then anchored = false |
3 | wait( 10 ) |
4 | if "CorrodedMetal" :remove() |
5 | end |
The script below is a much better way to both get an object's material and a much better way the destroy parts. I've labeled everything the script does. I have also made it so that way when the material changes it detects if the part is a certain material.
01 | local part = script.Parent -- Creates a variable for the part |
02 |
03 | if part.Material = Enum.Material.CorrodedMetal then -- Detects if the material is corroded metal |
04 | part.Anchored = false --unanchores the part |
05 | wait( 10 ) -- waits 10 seconds |
06 | part:Destroy() -- Destroys the part |
07 | end -- Ends the if statement |
08 |
09 | part.Changed:Connect( function () -- when the parts properties change it does a function |
10 | if part.Material = Enum.Material.CorrodedMetal then -- Detects if the material is corroded metal |
11 | part.Anchored = false --unanchores the part |
12 | wait( 10 ) -- waits 10 seconds |
13 | part:Destroy() -- Destroys the part |
14 | end -- Ends the if statement |
15 | end ) -- Ends the function |