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

My part wont destroy if the parts material is metal?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by
BashGuy10 384 Moderation Voter
4 years ago

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

0
Also, this is untested so if it doesn't work, ask me. BashGuy10 384 — 4y

Answer this question