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

if Parent.Material = "CorrodedMetal" 
then anchored = false
    wait(10)
    if "CorrodedMetal":remove()
end

1 answer

Log in to vote
0
Answered by
Uluomis 32
4 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.

local part = script.Parent -- Creates a variable for the part

if part.Material = Enum.Material.CorrodedMetal then -- Detects if the material is corroded metal
    part.Anchored = false --unanchores the part
    wait(10) -- waits 10 seconds
    part:Destroy() -- Destroys the part
end -- Ends the if statement

part.Changed:Connect(function() -- when the parts properties change it does a function
    if part.Material = Enum.Material.CorrodedMetal then -- Detects if the material is corroded metal
    part.Anchored = false --unanchores the part
    wait(10) -- waits 10 seconds
    part:Destroy() -- Destroys the part
end -- Ends the if statement
end) -- Ends the function
Ad

Answer this question