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?
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)
What?
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.
4 comments
BrickColor is a datatype, that function takes a string, in your case it should be "BrickColor" in quotation marks.
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild(”Humanoid”) then (the part here without brackets).BrickColor = Color3.new(color here) end end)
^ No
You'll get this error if you do that: "bad argument #1 to '?' (BrickColor expected, got Color3)"