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

How do I make something unanchored if the parent is a certain material?

Asked by 5 years ago

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.

1if Parent.Material = "CorrodedMetal"
2then anchored = false
3    wait(10)
4    if "CorrodedMetal":remove()
5end

1 answer

Log in to vote
0
Answered by
Uluomis 32
5 years ago

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.

01local part = script.Parent -- Creates a variable for the part
02 
03if 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
07end -- Ends the if statement
08 
09part.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
14end -- Ends the if statement
15end) -- Ends the function
Ad

Answer this question