Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make Spotlights and Part colors build a gradient and wont "jump" to the next color?

Asked by 5 years ago

Hello. I have the following problem:

I want to make my SpotLights and Parts color to change color smoothly. This is the script i made:

local SpotLight = workspace.Workspace1.Shop.ShopMisc.ShopSignLamp2

while wait(0.1) do
SpotLight.Color = Color3.fromRGB(0,0,0)
wait(0.5)
SpotLight.Color = Color3.fromRGB(0,255,38)
wait(0.5)
SpotLight.Color = Color3.fromRGB(20,12,255)
wait(0.5)
SpotLight.Color = Color3.fromRGB(255,66,240)
wait(0.5)
SpotLight.Color = Color3.fromRGB(20,255,27)
wait(0.5)
SpotLight.Color = Color3.fromRGB(114,255,112)
wait(0.5)
SpotLight.Color = Color3.fromRGB(255,149,0)
wait(0.5)
SpotLight.Color = Color3.fromRGB(0,0,0)
wait(0.5)
SpotLight.Color = Color3.fromRGB(85,255,0)
wait(0.5)
SpotLight.Color = Color3.fromRGB(255,0,179)
wait(0.5)
end

Is there a integer to form a gradient? Thanks!

1
Look into TweenService....https://developer.roblox.com/en-us/api-reference/class/TweenService ForeverBrown 356 — 5y

2 answers

Log in to vote
0
Answered by
TopBagon 109
5 years ago

Yeah, twinning is definitely one of the easiest ways to go, here's a little example:

local part = script.Parent
local TweenService = game:GetService("TweenService")

local colors = {
    Color = Color3.new(0,1,0)   
}

local info = TweenInfo.new(5, -- Speed
    Enum.EasingStyle.Cubic,Enum.EasingDirection.In,
    0, -- How many times should it repeat
    false, -- Should it go back to it's original color or not
    0) -- Delay between repetitions

local Tweening = TweenService:Create(part,info,colors)

Tweening:Play()

Just insert a part and put this script inside it, which will change the part color to green slowly (5 seconds to be exact but you can change that, I've added some comments but I'd still recommend reading the dev page that the comment above me says)

Good luck.

0
thanks! Aqua_LionHD 2 — 5y
Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Like ForeverBrown said, you can use TweenService to do something like this now.

local SpotLight = workspace.Workspace1.Shop.ShopMisc.ShopSignLamp2
local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
    3, -- Time
    Enum.EasingStyle.Linear, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    0, -- RepeatCount (when less than zero the tween will loop indefinitely)
    false, -- Reverses (tween will reverse once reaching it's goal)
    0 -- DelayTime
) 

local colors = {
    Color3.fromRGB(0,0,0);
    Color3.fromRGB(0,255,38);
    Color3.fromRGB(20,12,255);
    Color3.fromRGB(255,66,240);
    Color3.fromRGB(20,255,27);
    Color3.fromRGB(114,255,112);
    Color3.fromRGB(255,149,0);
    Color3.fromRGB(0,0,0);
    Color3.fromRGB(85,255,0);
    Color3.fromRGB(255,0,179)
}

while true do
    -- loop through colors
    for i,v in pairs ( colors ) do 
        local tween = TweenService:Create(SpotLight, tweenInfo, {Color = v})
        tween:Play()
        -- wait until tween is done to move on to next color
        tween.Completed:Wait()
    end
end

Answer this question