How to create a wave effect from left to right with rainbow color (UIGradient)

image

I want the reward text to be rainbow when someone gets a high reward but i cannot find out how to code the uigradient

UIGradients have an Offset property that you can use to get this wave effect.
Here’s an easy way to do it :

local Gradient = -- your UIGradient

while true do
    if Gradient.Offset.X > 1 then
        Gradient.Offset = Vector2.new(-1, 0)
    else
        Gradient.Offset = Vector2.new(Gradient.Offset.X + .05, 0)
    end
    wait(.01)
end

This way your gradient will constantly move to the very right of your TextLabel, then come back to the very left and so on.

1 Like

Here’s a script, put this into your UIGradient: (found this on a devforum post)

--//Services
local RunService = game:GetService("RunService")

--//Variables
local gradient = script.Parent

--//Controls
local time = 2 -- amount of time it takes to get from 0 to 1
local range = 10 -- amount of colors

--//Functions
RunService.Heartbeat:Connect(function()
	local loop = tick() % time / time
	local colors = {}

	for i = 1, range + 1, 1 do
		z = Color3.fromHSV(loop - ((i - 1)/range), 1, 1)

		if loop - ((i - 1) / range) < 0 then
			z = Color3.fromHSV((loop - ((i - 1) / range)) + 1, 1, 1)
		end

		local d = ColorSequenceKeypoint.new((i - 1) / range, z)
		table.insert(colors, d)
	end

	gradient.Color = ColorSequence.new(colors)
end)

Here’s a placefile for it so you can see it for yourself:
RainbowText.rbxl (39.5 KB)

1 Like

It’s smooth but can u explain why my code aint smooth

I coded it using my own method but it looks like its “teleporting”

image

Video:

image
You’re changing i by -0.05 there, but it needs to increase; your second for loop is just skipped.
It should work if you set 0.05 instead

You can even make the code shorter :

while wait() do
    for i = -1, 1, 0.05 do
        script.Parent.Offset = Vector2.new(i, 0)
        wait(.01)
    end
end

I know but isn’t it a negative value and it has to decrease to positive values