✓ Accepted answer
The reason this isn't working as expected is because you only generate a random number once; you want a new random position to be chosen each time. To accomplish this, you need to call math.random() in each iteration.
local Pic = script.Parent
local movetime = 3
while wait(5) do
local NextMoveVert = math.random(.25,.35)
local NextMoveHorz = math.random(0.45,0.35)
Pic:TweenPosition(UDim2.new(NextMoveHorz, 0, NextMoveVert, 0), "InOut", "Quint", movetime)
end
Hope this helped.
EDIT: In a rush to correct the obvious issue, it seems I missed a few others.
First, your range of numbers is small-- .25-.35 and .35-.45. The difference will be small if you choose these numbers.
Secondly, math.random rounds non-integer values to the nearest integer; that is, decimals aren't accepted.
Finally, in your second math.random call, the larger number is before the smaller number, when it should be the other way around. You can fix these issues with a little bit of math (and switching two numbers around):
local Pic = script.Parent
local movetime = 3
while wait(5) do
local NextMoveVert = math.random(25, 35)/100;
local NextMoveHorz = math.random(35, 45)/100;
Pic:TweenPosition(UDim2.new(NextMoveHorz, 0, NextMoveVert, 0), "InOut", "Quint", movetime)
end
Hope this helped.
2 comments
Everyone keeps saying the same answer, but I still get the same problem. Please test your answer before submitting...
Sorry about that! I've added an edition.