Skinstashery
Roblox
Home / Roblox / Studio script library / Random colour changer
RB-004

Roblox random colour changer script

Changes the colour of every part in a folder to a new random colour every few seconds.

Script type
Script
Where it goes
ServerScriptService
Category
World and effects

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Random colour changer: every part in the folder gets a new colour on a timer.

local FOLDER_NAME = "ColorParts"   -- a Folder in the Workspace that holds your parts
local INTERVAL = 3                 -- seconds between changes
local FADE_TIME = 1                -- seconds each colour takes to blend

local TweenService = game:GetService("TweenService")

local folder = workspace:WaitForChild(FOLDER_NAME)

while true do
	for _, child in folder:GetDescendants() do
		if child:IsA("BasePart") then
			local newColor = Color3.fromHSV(math.random(), 0.7, 1)
			TweenService:Create(child, TweenInfo.new(FADE_TIME), { Color = newColor }):Play()
		end
	end
	task.wait(INTERVAL)
end

How to set it up

  1. In the Explorer, right-click Workspace, choose Insert Object, then Folder. Name it ColorParts.
  2. Drag the parts you want to change into that folder.
  3. Add a Script to ServerScriptService and paste the code.
  4. Play and watch them change.

Change it

More in World and effects

All Roblox scripts

More Roblox tools