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

Why wont this script work properly?

Asked by 8 years ago
local part = script.Parent
part.Touched:connect(function(hit)
    if hit.Parent then
        if hit.BrickColor == "Dark orange" and hit.Material == "Wood" then
            hit.Parent.BrickColor = BrickColor.Black()
        end
    end
end)

It's supposed to, when a part is made of dark orange wood, "burn" it. There are no errors in the output.

Thank you in advance for any help you may provide.

1 answer

Log in to vote
0
Answered by
yoshi8080 445 Moderation Voter
8 years ago

You forgot to check if a humanoid has checked it, you use ontouch function and get the parent of what hit it returning the humanoid.

function onTouch(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid") -- used to find humanoid in player ontouch
    local block = script.Parent
    if (humanoid ~= nil) and block.Material == Enum.Material.Wood and block.BrickColor == BrickColor.new('Bright orange') then -- Enum to check material requirement, BrickColor.new for part color requirement
        block.BrickColor = BrickColor.new('Black')
    end
end
script.Parent.Touched:connect(onTouch)
Ad

Answer this question