Hello, I’ve been learning how to script, and ive gotten to this point where i was wondering:
Is it possible to get a for loop to change the color of a brick gradually, based on values in a table. for example
local MainFolder = game.Workspace.Testttt
local MainChildren = MainFolder:GetChildren("Parts")
local MyTable = {Color3.fromRGB(165, 0, 0), Color3.fromRGB(165, 0, 2)}
while true do
for i, v in pairs(MainChildren)do
v.BrickColor = ??????????????????????????????????
end
end```
--[If it's possible, how would i go about writing it in the script? i cant seem to find anything on the Wiki...
I am aware that i could use tweening, but i am trying to understand for loops better before advancing further. :) thanks.
You can use Color3:lerp() to produce this effect without tweening. This example will cycle through red, green, and blue.
local Colors = {Color3.fromRGB(150, 0, 0), Color3.fromRGB(0, 150, 0), Color3.fromRGB(0, 0, 150)}
for _, NewColor in pairs(Colors) do
for Alpha = 0, 1, 0.05 do
Object.Color = Object.Color:lerp(NewColor, Alpha)
wait()
end
end
Alpha basically refers to what proportion of the NewColor is present; for instance, an Alpha value of 0.5 would mix the colors evenly.
function gui:colour_change_frame(trans,colour,speed)
local TweenService = game:GetService("TweenService")
local goal = {}
goal.BackgroundColor3 = colour
local tweenInfo = TweenInfo.new(speed) --duration
local tween = TweenService:Create(trans, tweenInfo, goal)
tween:Play()
end
Here is some old module function I wrote that does this. Just use this, but make sure you change the goal.