Is there a way to make the math.random change every tween played?

Hello there! I wanted to know if it is possible to change the amount of time the a tween plays using math.random. The script works but it seems as if the math.random function triggers only once then uses that random number thorought the full tween for the rest of its time being played.

Here is the script I got, I’m trying to get the number to change every time the tween is played but I’m unsure of why this isn’t working. If you could help, thanks! :smile:

local Image = script.Parent.BrightShade


do
	local random1 = math.random(0.5, 2.2)
	local random2 = math.random(0.7, 4)
	
	
	local tweenInfo = TweenInfo.new(
	random1, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	random2 -- DelayTime
	)
	
local tween1 = TweenService:Create(Image, tweenInfo, {ImageTransparency = .98})

	
	tween1:Play()
	end

Why is there a random do? And is this your entire script?

Yes it is, I added do so it can change over the math.random everytime it is played, but it doesn’t work. And this is the entire script.

You can make a table with all the tween and can do table.remove(table, math.random(#table))

1 Like

Not sure what you mean, mind sending an example?

Won’t that just be 0 or 1 or 2… (using roblox lua)
Also do is just for scopes
Is this in a loop? It is only suppose to play the tween once,

If you want the random to change its order every time you rejoin then you should write this on line one:

math.randomseed(tick())

To get decimal random numbers I would do this:

math.random(5,22)/10

You could just do a math.random() between 0 and 1 and pick which number to use:

TweenInfo.new(
  (math.random(2) - 1) == 0 and random1 or random2,
-- blah blah
)

It plays then reverse, then plays again. In a loop.

You could nest the TweenInfo constructor.

local Image = script.Parent.BrightShade
	
TweenService:Create(
    Image, 
    TweenInfo.new(
       math.random(0.5, 2.2), -- Time
       Enum.EasingStyle.Linear, -- EasingStyle
	   Enum.EasingDirection.Out, -- EasingDirection
	   -1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	   true, -- Reverses (tween will reverse once reaching it's goal)
	   math.random(0.7, 4) -- DelayTime
	),
    {ImageTransparency = .98}
):Play()