Button not moving properly

  1. What do you want to achieve?
    I need for this button to move to a random position every time it’s clicked.

  2. 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.

  3. 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)

Help would be much appreciated

1 Like

I don’t think “Activated” is a function for TextButtons or ImageButtons, if that is what you are experimenting with. Try changing that to this,;

button.MouseButton1Down:Connect(function()

Instead.

1 Like

It does the exact same thing as activated. Problem still persists

1 Like

Could you send a place file over?

1 Like

I can later. I’m busy right now and not able to send it.

1 Like

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)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.