Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.