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

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

Asked by 5 years ago

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?

0
[BrickColor is a datatype](https://developer.roblox.com/api-reference/datatype/BrickColor), that function takes a string, in your case it should be "BrickColor" in quotation marks. frickmyposterior 20 — 5y
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) Gameplayer365247v2 1055 — 5y
0
^ No DeceptiveCaster 3761 — 5y
0
You'll get this error if you do that: "bad argument #1 to '?' (BrickColor expected, got Color3)" DeceptiveCaster 3761 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Log in to vote
0
Answered by 5 years ago

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)
0
What? DeceptiveCaster 3761 — 5y
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. DeceptiveCaster 3761 — 5y

Answer this question