Haven’t scripted in a while and I’m trying to figure out how to have the randomness value change every time the tween plays so that the animation is different every time, currently whenever I play the tween the randomness value stays the same as last time it played.
local TweenService = game:GetService("TweenService")
local Gui = script.Parent
local info = TweenInfo.new(
2, --Length
Enum.EasingStyle.Bounce, --Type of Tween (easing style)
Enum.EasingDirection.Out, --Easing Direction
0, --Ammount of times it repeats
false, --Reverse? (go back up)
0 --Delay
)
local Goals =
{
Position = UDim2.new(math.random(), math.random());
}
local ButtonTween = TweenService:Create(Gui, info, Goals)
script.Parent.MouseButton1Click:Connect(function()
ButtonTween:Play()
end)
Assuming you are trying to change Scale (not offset) math.random won’t work unless you do math.random(1, 100)/100 (then it would work), as scale runs on a singular digit format, which Math.random can’t do decimals.
As for your code, you would probably need to run the random everytime the button is clicked.
For example -
local TweenService = game:GetService("TweenService")
local Gui = script.Parent
local info = TweenInfo.new(
2, --Length
Enum.EasingStyle.Bounce, --Type of Tween (easing style)
Enum.EasingDirection.Out, --Easing Direction
0, --Ammount of times it repeats
false, --Reverse? (go back up)
0 --Delay
)
script.Parent.MouseButton1Click:Connect(function()
local ButtonTween = TweenService:Create(Gui, info, {Position = UDim2.new(math.random(1, 100)/100, 0, math.random(1, 100)/100, 0)})
ButtonTween:Play()
end)
There’s more to it than that, obviously as random isn’t always random, would be best to implement a math.randomseed(tick()) at the start too.