Tweening UI is not working

  1. I am trying to tween a UI to a random position.

  2. Everything seems to be working except that it tweens to the same place every time as if I’m not doing math.random()

https://gyazo.com/c04fc558d7f1af026c5070e3c68087ba

local goals = {
	Position = UDim2.new(math.random(0,0.8),0,math.random(0,0.8),0) ,
	ImageTransparency = 0.7
}

math.random doesn’t work with decimals if I remember well, you’d need to do math.random(0,8) / 10 for every math.random(0,0.8) you have, or use the Random Class and just use :NextNumber(0, 0.8)

1 Like

I see. Not sure how to implement it tho. Could you help me out?

Either

local goals = {
	Position = UDim2.fromScale(math.random(0,8) / 10,math.random(0,8) / 10),
	ImageTransparency = 0.7
}

Or

local rand = Random.new()

local goals = {
	Position = UDim2.fromScale(rand:NextNumber(0, 0.8), rand:NextNumber(0, 0.8),
	ImageTransparency = 0.7
}

From your use case, you probably want the 2nd one


hmm doesn’t seem to work

My bad, forgot a bracket

local rand = Random.new()

local goals = {
	Position = UDim2.fromScale(rand:NextNumber(0, 0.8), rand:NextNumber(0, 0.8)),
	ImageTransparency = 0.7
}
1 Like

still goes like the other one. It does not tween in a random position in tweens in the same one over and over again

btw I want it to be random for every different click. I am probably doing something wrong

Are you ever recreating the goals variable? Form the looks of it, you use the same one, thus will mean you use hte same location it randomly chose. You have to remake it when you need to tween

1 Like

yeah. I got to find a way to randomize it for every click.

Just put it in the function that happens when you click?

1 Like

Fixed it. Thanks for the help!! I just needed to do this instead.

local fistImageTween = tweenService:Create(rfistImage, tweenInfo, {Position = UDim2.fromScale(rand:NextNumber(0, 0.8), rand:NextNumber(0, 0.8)),
		ImageTransparency = 0.7})
1 Like