[UNSOLVED] Gradient Pillar / GetInstance Issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear! The example is shown in this video:

  2. What is the issue? Include screenshots / videos if possible!
    When using get instance, to do like wait() it will do it one part at a time, but not instantly like the pillar in this video.

local TweenService = game:GetService("TweenService")

-- Function to tween color
local function tweenColor(part, endColor, duration)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tween = TweenService:Create(part.SurfaceGui.ImageLabel, tweenInfo, {ImageColor3 = endColor})
	tween:Play()
end

-- Get the model and its parts
local model = game.Workspace.NeonPillars

local function onClicked()
	wait(4)
	local parts = model:GetChildren()
	for i = 1, 53 do
		for i2, part in pairs(model:GetChildren()) do
			if part.Name == tostring(i) then
				tweenColor(part, Color3.fromRGB(59, 24, 112), 1.2)  
wait()
	tweenColor(part, Color3.fromRGB(0,0,0), 1.2)  
			end
		end

		task.wait() 
	end
end
script.Parent.MouseButton1Click:Connect(onClicked)

An issue I’ve had for a while.

bump, cause i generally dont know.

Bit of a tricky problem, this is the solution I ended up with:

local gradient = script.Parent.SurfaceGui.Frame.UIGradient

local speed = .01

local oldColorSequencePoints = gradient.Color.Keypoints
local newColorSequencePoints = {}

while true do
	
	newColorSequencePoints = {}
	
	-- Generate a new sequence of color points by offseting the time
	for _, keypoint in oldColorSequencePoints do
		local newKeypointTime = keypoint.Time - speed;
		if newKeypointTime < 0 then
			newKeypointTime += 1
		end 
		table.insert(newColorSequencePoints,
			ColorSequenceKeypoint.new(newKeypointTime, keypoint.Value)
		)
	end
	
	-- Sort by time
	table.sort(newColorSequencePoints, function(a, b)
		return a.Time < b.Time
	end)
	
	-- Saving the the sequence before any added points
	oldColorSequencePoints = table.clone(newColorSequencePoints);
	
	-- Added 0 and 1 points if they don't exist
	-- Lerp the color to find the exact color that should be at the starting / end points
	local firstPoint = newColorSequencePoints[1]
	local lastPoint = newColorSequencePoints[#newColorSequencePoints];
	if firstPoint.Time ~= 0 then
		table.insert(newColorSequencePoints, 1, ColorSequenceKeypoint.new(
			0, 
			firstPoint.Value:Lerp(
				lastPoint.Value,
				firstPoint.Time / (1 - lastPoint.Time + firstPoint.Time)
			)))
	end
	if lastPoint.Time ~= 1 then
		table.insert(newColorSequencePoints, ColorSequenceKeypoint.new(
			1,
			firstPoint.Value
		))
	end
	
    -- Assign color
	gradient.Color = ColorSequence.new(newColorSequencePoints);
	task.wait()
end

1 Like

No UIGradient was used here, it’s just parts labeled from 1 - 53, and its j ust parts that’s what I need help with, I can’t do wait() cause it would then tween 1 - 53 slowly or randomly, i want it done within the tween duration.

Might need to bump this, still having the issue.

This code makes me uncomfortable because you use two different types of wait. Always use task.wait(), it’s more accurate.

Besides that, your problem is most likely because you’re running all the code subsequently. Try using a thread (task.spawn()), to run all of the code at the same time, assuming there are a lot of parts, you’ll see a difference because instead of doing one part per frame, you start multiple per frame, and it’s faster.

Note that this isn’t going to be recommended, though with TOO many parts because it can become taxxing to spawn that many threads simultaneously.

Even if you don’t want to do this, I think just switching to task.wait() will give you a good performance boost in itself, it runs at twice the hertz as the former.

I see you are using multiple waits to prevent a script timeout, but you really only need one inner one. Try taking out the last task.wait(), this should also shed some time.

I’m gonna be honest, I use task.wait more but I actually don’t know why the code has, “wait()”; might be an error when I was using “Code Replacer” plugin, but I’ll try that.

Alright that solves the GetInstance issue, It’s now the Gradient bit we need to get working since in the original clip I’ve sent it does 4 colors; Purple, Yellow, White, Black. How would I make it act like the video?

local TweenService = game:GetService("TweenService")



local function tweenColor(part, endColor, duration)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tween = TweenService:Create(part.SurfaceGui.ImageLabel, tweenInfo, {ImageColor3 = endColor})
	tween:Play()
end


local model = game.Workspace.NeonPillars

local function onClicked()
	task.spawn(function()
		task.wait(4)
		local parts = model:GetChildren()
		for i = 1, 53 do
			for i2, part in pairs(model:GetChildren()) do
				if part.Name == tostring(i) then
					task.spawn(function()
						tweenColor(part, Color3.fromRGB(59, 24, 112), 1.2)
						task.wait(.5)
						tweenColor(part, Color3.fromRGB(255, 170, 0), 1.2)
						task.wait(.3)
						tweenColor(part, Color3.fromRGB(255, 255, 255), 1.2)
					end)
				end
			end
			task.wait()
		end
	end)
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

Bump, since I’m still having the issue.

same thing atm, since i’m trying to figure out how to make it seamlessly flow, like that.