Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change colors to a different shade?

I tried to make a disco floor that changes color so I looked up how, I got the idea to make it change colors randomly but I want it to be smooth, how would I do this?

Code I used: while true do script.Parent.BrickColor = BrickColor.Random() wait(0.5) end

3 comments

0

Tweening.

0

Do you want to make the colors smooth?

0

No, he means smooth transitions.

1 answer

✓ Accepted answer

The easiest way to randomize a part's color is to tween its color property using TweenService.

local TweenService = game:GetService("TweenService")

local Part = workspace.Part

local TweenSettings = TweenInfo.new(
	2, --Duration of the tween.
	Enum.EasingStyle.Linear, --Tweening Style
	Enum.EasingDirection.InOut, --Tweening Direction
	0, --How much the tween should repeat.
	false, --Do not reverse tween after it started.
	0 --No delay time.
)

while true do
	--Create the tween using TweenService:Create()
	--1st argument: Instance to be tweened.
	--2nd argument: The Tween Settings.
	--3rd argument: Dictionary of the properties to be tweened.
	--BrickColor cannot be tweened, so tween the Color property.
	local Tween = TweenService:Create(Part, TweenSettings, {Color = BrickColor.Random().Color})

	--Play tween.
	Tween:Play()
	--Wait for the tween to complete.
	Tween.Completed:Wait()


end

2 comments

0

I don't know why there is a random call to wait at line 26? Also why are you calling it with no arguments? This is a code smell.

0

Hmm, probably just a habit when using while true do. I removed it.

This discussion is preserved as it was. New answers, comments, and votes are closed.