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

brick color changing GUI not working?

Asked by 3 years ago

rn i am trying to make a gui that when clicked changes the color of a part. this is the script i have right now

script.Parent.MouseButton1Click:Connect(function(player)
    game.Workspace.ColorPart.BrickColor = Color3.new(0, 0, 0)
end)

but my output just says:

20:01:19.421 - Players.mynam3with123.PlayerGui.ScreenGui.TextButton.LocalScript:2: invalid argument #3 (BrickColor expected, got Color3)

1
Conflicting datatypes, you need to supply a BrickColor Object. You can construct a new one like so: BrickColor.new(string BrickColor) Ziffixture 6913 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

As Feahren already explained perfectly in their comment, you are supplying an invalid datatype to the property you are trying to change.

A part's BrickColor requires BrickColor.new(number val)

However, if you would like to get away from using a BrickColor datatype (I know I do), then you could simply take advantage of the fact that most part objects now have a Color property that can be supplied a Color3 datatype!

Therefore, your new code could look like this!

local GUI_Object = script.Parent
local ColorPart = game.Workspace.ColorPart

GUI_Object.MouseButton1Click:Connect(function(player)
    ColorPart.Color = Color3.new(0, 0, 0)
end)

I hope this helps!

Ad

Answer this question