module script:
local colorsmodule = {
Color3.fromRGB(255, 0, 0),
Color3.fromRGB(0, 0, 255),
Color3.fromRGB(0, 255, 0),
Color3.fromRGB(255, 255, 0),
Color3.fromRGB(0, 255, 255),
Color3.fromRGB(255, 0, 255),
}
return colorsmodule
script:
Rainbow = workspace.RainbowPart
local colors = require(workspace.ModuleScript)
task.spawn(function()
while task.wait(0.25) do
Rainbow.Color = colors[Random.new():NextInteger(1, #colors)]
end
end)
basically, you should do Color3.fromRGB()
when using rgb colours.
Brickcolor.random()
picks a random colour from Brickcolor.palette()
.
module scripts cannot run on their own.
for them to run, they must be called by another script using require()
.
also, they MUST return something. In this case, a table.
This table includes the colours we set.
You do not need a .Touched
event to change its colours forever - what if it is in the air? just use a while loop.
task.spawn
is a bit advanced so I wonāt explain it.
wait()
is deprecated. meaning it is no longer supported. it has been replaced by task.wait()
. use that instead
Random.new():NextInteger()
ensures that have a truly random number. If you didnāt know, roblox doesnt have random numbers, but generated lines of numbers called āseedsā. Random.new()
with no parameters, the things you put in the (), generates a random seed.
Links:
Brickcolor.palette()
Brickcolor.random()
Color3.fromRGB()
Random.new()
:NextInteger()
task.wait()
task.spawn()
while loops
.Touched
require()
module script