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

Changing color of a part perfectly?

--Locals--/--Properties--
--Made by The Tray Team--
local Part = script.Parent

--Script--
while true do --To loop
Part.Material = Enum.Material.Neon
Part.BrickColor = BrickColor.new(17, 17, 17)
wait (2)
Part.BrickColor = BrickColor.new(255, 0, 0)
wait (2)
Part.BrickColor = BrickColor.new(255, 255, 0)
wait (2)
Part.BrickColor = BrickColor.new(0, 16, 176)
wait (2)
Part.BrickColor = BrickColor.new(0, 255, 0)
wait (2)
Part.BrickColor = BrickColor.new(180, 210, 228)
wait (2)
Part.BrickColor = BrickColor.new(255, 152, 220)
wait (2)
Part.BrickColor = BrickColor.new(0, 255, 127)
	end

This script represents a normal changing of color. THe problem is, is it possible to make way more, smoother? Like before changing any color, it changes it slowly so it make it more cooler or something? Please help!

5 comments

0

use tweenservice

0

Yeah but how. I can do it in Gui and Moving parts but not in changing colors..

0

If you want to have a transition effect for the colors that requires a bit of math and a for loop.

0

Or of course you could do it manually which i wouldnt reccomend

0

for the sake of sanity of course

2 answers

✓ Accepted answer

As thesquid13 said, use TweenService. You can find out how on the wiki. This page from the dev wiki has this code example for you:

local TweenService = game:GetService("TweenService")
 
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Color = Color3.new(1, 0, 0)
part.Anchored = true
part.Parent = game.Workspace
 
local goal = {}
goal.Position = Vector3.new(10, 10, 0)
goal.Color = Color3.new(0, 1, 0)
 
local tweenInfo = TweenInfo.new(5)
 
local tween = TweenService:Create(part, tweenInfo, goal)
 
tween:Play()

This example tweens both the color AND the position, but you can adapt it to your needs.

1 comment

0

Thanks!

I use TweenService quite frequently, and to simplify it, I have created a neat and compact tweening function that works in almost any scenario.

local tween = function(itemtotween,property,value,tweentime,easingstyle,easingdirection)
	local info = TweenInfo.new(tweentime,Enum.EasingStyle[easingstyle],Enum.EasingDirection[easingdirection],0,false,0)
	local goal = {}
	goal[property] = value
	return game:GetService("TweenService"):Create(itemtotween,info,goal)
end

while true do --A little example of what you can do
	tween(game.workspace.Part, "Color", Color3.new(0,0,0), 1, "Quad", "InOut"):Play()
	wait(1)
	tween(game.workspace.Part, "Color", Color3.new(1,1,1), 1, "Quad", "inOut"):Play()
	wait(1)
end

--[[
Side note: You'll have to put the property into a string, so instead of game.workspace.Part.Color you do game.workspace.Part, "Color"
--]]

1 comment

0

adding to the side note, you'll also need to put the easingdirection and easingstyle in a string

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