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

My part wont destroy if the parts material is metal?

There might be something wrong with the = sign but I couldn't fix it please help.




	script.Parent.Touched:Connect(function()
		script.Parent.BrickColor = BrickColor.new("Black")
		script.Parent.Material = ("Metal")
	end)


if
script.Parent.Material = ("Metal")
then

script.Parent:Destroy()

	wait(0.5)
	
end


2 answers

✓ Accepted answer

There are some problems on this script. Right on the beggining you set the Touched event to change the color and material of the block, not destroy it.

script.Parent.Touched:Connect(function()
        script.Parent.BrickColor = BrickColor.new("Black")
        script.Parent.Material = ("Metal")
    end)

With that in mind, your script just checks if the part that holds the script has Metal material as soon as the script runs:

if
script.Parent.Material = ("Metal")
then

script.Parent:Destroy()

    wait(0.5)

end

To fix this you should change some of the order on your script. Also set a double = on if script.Parent.Material = ("Metal") and change ("Metal") to Enum.Material.Metal:

script.Parent.BrickColor = BrickColor.new("Black")
script.Parent.Material = ("Metal")
script.Parent.Touched:Connect(function()
     if script.Parent.Material == Enum.Material.Metal then
           script.Parent:Destroy()
           wait(0.5)
     end
end)

Do you want the part that holds the script to be destroyed or the part that touched it? If its the part that touched it, you should give a name to that part inside the function parentheses and use that name to reference it:

script.Parent.BrickColor = BrickColor.new("Black")
script.Parent.Material = ("Metal")
script.Parent.Touched:Connect(function(touchedPart)
     if touchedPart.Material == Enum.Material.Metal then
           touchedPart:Destroy()
           wait(0.5)
     end
end)

If you want the part that holds the script to be deleted, change the fifth line to script.Parent:Destroy(). This should work, but if it doesn't, answer me with the error that ocurred on the output window and I will fix it.

Try this, ok?

debris

touched

script.Parent.Touched:Connect(function()
	script.Parent.BrickColor = BrickColor.new("Black")
	script.Parent.Material = ("Metal")
end)


while true do
	wait(0.25) -- To make sure it does not crash the game
	if script.Parent.Material = ("Metal") then
		game:GetService("Debris"):AddItem(script.Parent, 0.50) -- Because maybe it would screw up something and error
	end
end

1 comment

0

Also, this is untested so if it doesn't work, ask me.

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