Script :
local function onTouch(hit) end game.Workspace.Part.BrickColor = math.random()
error : 21:24:22.193 - Workspace.Part.Script:5: invalid argument #3 (BrickColor expected, got number)
math.random()
has no arguments, therefore it will randomly generate a real number between 0 and 1.
You are setting the "BrickColor" property of your part to a number between 0 and 1.
Here is a list of BrickColor Codes for reference List of BrickColor Codes
If you want to randomize the colour there are 2 options I can recommend.
Color3.fromRGB() -- Ranges from 0-255 per value BrickColor.random() -- Gives a random brick colour from the preset colours
So you'd want to change your code to something like this
game.Workspace.Part.BrickColor = BrickColor.random()
or
local r, g, b = math.random(0, 255), math.random(0, 255), math.random(0, 255) -- Randomizes 3 values from 0 to 255 game.Workspace.Part.Color = Color3.fromRGB(r, g, b) -- Creates a colour using the 3 values from earlier
I would recommend the latter option (Color3.fromRGB) as it is more random than the former (BrickColor.random).
Tip for the poster: I'd advise you to look at articles that have already been addressed as this question is one of a kind question that has been covered at least thrice or more. These include: Documentations from the developer hub, dev forums, "Scripting Helpers!"
Brick colors are ran through three different values and those are the three primary colors (red green blue) . You are giving the script one value and there for the script can’t change the value without all three values given. Try doing this
Local red = math.random() Local green = math.random() Local blue = math.random() game.workspace.part.brickcolor = brickcolor.new(red, green, blue)