Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Tweening Random Color Not Working?

I am trying to make a part turn a random Color3 every few seconds using TweenService. But when I test the game the color doesn't change at all and there are no errors. Here is my script inside the part:

while true do
	wait()
	local color1 = math.random(0,255)
	local color2 = math.random(0,255)
	local color3 = math.random(0,255)
	local ts = game:GetService("TweenService")
	local p = script.Parent
	local ti = TweenInfo.new(5,Enum.EasingStyle.Elastic,Enum.EasingDirection.In,99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999,true,0) --I set the number so high because I want it to always replay
	local pp = {
	
	Color = Color3.fromRGB(color1,color2,color3)
	
	}
end

If someone could tell me what is wrong that would be greatly appreciated. Thanks in advance!

-PrismaticFruits

4 comments

0

Can you include the code where you are creating and playing the tween? I only see you making tween info and goals, but no tween.

0

Oh! That was the problem lol. I forgot to make a tween :/

0

:D Don't you love when that kind of stuff happens? You sit there staring at your code wondering why it won't work, and the moment you bring it to someone else they point out the fact that you didn't call a function or something.

0

XD

1 answer

✓ Accepted answer

To make this constructive for other people:

    local color1 = math.random(0,255)
    local color2 = math.random(0,255)
    local color3 = math.random(0,255)
    local ts = game:GetService("TweenService")
    local p = script.Parent
    local ti = TweenInfo.new(5,Enum.EasingStyle.Elastic,Enum.EasingDirection.In,-1,true,0) -- bad practice to set the number high, just set it to -1 if you want it to repeat forever
    local pp = {

    Color = Color3.fromRGB(color1,color2,color3)

    }
local tween = ts:Create(p, ti, pp)
tween:Play()

I actually also found some problems with your code, the comment I attached to your tween info, and the fact that if you have a tween loop via your tweeninfo, then there's no reason to put it in a while true loop.

If you want it to play, then stop and wait, and play again, you would change that -1 to 0, and then put the whole thing back in a while true loop with a wait() somewhere in it.

If you don't care about the easing style and you want it to look like it paused for just a second, you could change it to EasingStyle.Exponential.

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.