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?
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:
1 | script.Parent.Touched:Connect( function (part) |
2 | if script.Parent.BrickColor ~ = part.BrickColor then |
3 | script.Parent.BrickColor = part.BrickColor |
4 | end |
5 | 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
1 | script.Parent.Touched:Connect( function (hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
3 | script.Parent.BrickColor = part that has a set color here.BrickColor |
in my case i did this
1 | script.Parent.Touched:Connect( function (hit) |
2 |
3 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
4 |
5 | script.Parent.BrickColor = game.Workspace.test.BrickColor |
6 |
7 | end |
8 |
9 | end ) |