Rainbow text script having problems

The problem here is that whenever I have 1 or more rainbow things. It will mess up. For example: I have two different scripts constantly changing the color for a gui, but every now and then a Gui color will freeze. Is there anyway to fix this?

image
^^
Despite the scripts beings loaded at the same time. One will always freeze.

On top of that the scripts will freeze up other scripts. I have an intermission script and when intermission happens it will freeze on a number and then randomly continue. This happens despite all the rainbow scripts being in a separate place. I have no idea what to do to fix this.

local t = 5; 
		spawn(function()
			while wait(0.1) do
				local hue = tick() % t / t
				local color = Color3.fromHSV(hue, 1, 1)
				title.TextColor3 = color
			end
		end)

why would a totally separate script freeze up others?
I checked script performance and its using up less then 0.1%

1 Like

The issue it could be is that you’re using spawn, which is known to be problamatic, I recommend converting it to a coroutine

local t = 5; 

local rainbowloop = coroutine.wrap(function()
	while wait(0.1) do
		local hue = tick() % t / t
		local color = Color3.fromHSV(hue, 1, 1)
		title.TextColor3 = color
	end
end

rainbowloop()
1 Like

still freezes up intermission timer, is it because I don’t have it in a local script?

It could be, try converting it to a localscript and seeing how it goes

Actually thats not the problem, for some reason the script is taking up nearly 10% of script activity. Idek why

Hmm, how many of them are there in the game? 2?

there is only one in the game, but it takes up alot of script storage

And it’s just that code that I sent you’re using correct? Maybe try to increase the wait time?

I found the problem, I had it so that whenever the textLabel was changed it redid the whole thing over again. So I had to add a debounce for whenever the colors were changing.

local title = script.Parent

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, true, 0)

local inLoop = false

title.Changed:Connect(function()
	if title.Text == "Tester" then
		title.TextColor3 = Color3.fromRGB(75, 255, 10)
	elseif title.Text == "Owner" and inLoop == false then
		local t = 5; 
		local rainbowloop = coroutine.wrap(function()
			while wait(0.01) do
				local hue = tick() % t / t
				local color = Color3.fromHSV(hue, 1, 1)
				title.TextColor3 = color
			end
		end)
		rainbowloop()
	end
	if title.Text == "Owner" then
		inLoop = true
	else 
		inLoop = false
	end
end)

if there is a better solution to this let me know.

I think that way you did it should be good. I would change

if title.Text == "Owner" then
		inLoop = true
	else 
		inLoop = false
	end

to

inloop = (title.Text == "Owner") and true or false

If it doesn’t work, try swapping the true and false around