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:
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)