What do you want to achieve?
I need for this button to move to a random position every time it’s clicked.
What is the issue?
When you first click the button, it will go to the top left corner of the UI, but will stay there even if you click it again. There are no errors.
What solutions have you tried so far?
I have tried making the random positions for the button variables, but that did not work either.
button.Activated:Connect(function()
script.Mix:Play()
local posX = math.random(0.2,0.8)
local posY = math.random(0.2,0.8)
quality += 1
button.Position = UDim2.new(posX, posY)
end)
UDim2.new() is supposed to have 4 parameters, not 2. Use UDim2.fromScale() instead. math.random also can’t generate floats, you will have to divide by 10 or use Random:NextNumber().
Code:
local RNG = Random.new()
button.Activated:Connect(function()
script.Mix:Play()
quality += 1
local posX = RNG:NextNumber(0.2, 0.8)
local posY = RNG:NextNumber(0.2, 0.8)
button.Position = UDim2.fromScale(posX, posY)
end)