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

How Do You Make A Brick Have The Same Color As Another Part On Touch???

script.Parent.Touched:Connect(function(parts) local color = parts:FindFirstChild(BrickColor) script.Parent.BrickColor = color end)

23:56:28.216 - Unable to cast value to std::string

-- any help?

4 comments

0

BrickColor is a datatype, that function takes a string, in your case it should be "BrickColor" in quotation marks.

0

script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild(”Humanoid”) then (the part here without brackets).BrickColor = Color3.new(color here) end end)

0

^ No

0

You'll get this error if you do that: "bad argument #1 to '?' (BrickColor expected, got Color3)"

3 answers

Use script.Parent.BrickColor = parts.BrickColor instead script.Parent.BrickColor = color

If you didn't know already, the parameter that Touched passes when it fires is the BasePart that touched the part firing the event. Through this, you can easily access the properties of that BasePart and set the BrickColor equal to the other part's color.

Example:

script.Parent.Touched:Connect(function(part)
    if script.Parent.BrickColor ~= part.BrickColor then
	    script.Parent.BrickColor = part.BrickColor
    end
end)

You can also use a part's Color property to match the two parts. But since we are talking about BrickColors, it's likely not worth mentioning, yet it works the same exact way with BrickColors as it does with Color3's.

correction to the script i pasted this is the correct script i also tested so it works and ofcourse it does

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
script.Parent.BrickColor = part that has a set color here.BrickColor

in my case i did this

script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then

script.Parent.BrickColor = game.Workspace.test.BrickColor

end

end)

2 comments

0

What?

0

You don't need to detect a Humanoid. If the part is generic and is not a part of the player's Character then you should not detect a Humanoid.

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