Math.random color changer

Im trying to make the part turn into a random color using math.random

The thing wont work because it says unkown global
im really new to scripting so it might be a dumb mistake.

local part = script.Parent

script.parent.color(R,G,B)
R = math.random()
G = math.random()
B = math.random()
1 Like

R, G and B was only defined after you changed the colour, so at the time you changed it they didnt exist

local part = script.Parent;

local R = math.random(1,255);
local G = math.random(1,255);
local B = math.random(1,255);

part.Color = Color3.fromRGB(R, G, B)
3 Likes

The RGB spectrum on Roblox only consists of values from 0 to 255, which will be plugged into a property of the BasePart. There are multiple ways to introduce color to a part, here is the documentation for it.

Refer to @asherppan for a scripted solution

you can use :

script.Parent.BrickColor = BrickColor.Random()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.