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

Why wont this script work properly?

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

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)

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