How would I make this gui at a random position on click

I’m trying to make a button go to a random position on screen when the player clicks it!
Issue: "The error causing the button to not move*

Errors: Players.ItsPlasmaRBLX.PlayerGui.ScreenGui.TextButton.Script:2: invalid argument #1 to ‘new’ (number expected, got table)

Code:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Position = Random:new()
end)
1 Like

What is Random:new()?

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Position = UDim2.new(math.random(), 0, math.random(), 0)
end)

you might want to use math.clamp so the gui doesn’t start clipping off the edge, math.random will give a random number between 0 and 1, if ti is 0.98, the gui will be off the scren so

script.Parent.Position = UDim2.new(math.clamp(math.random(), 0.2, 0.8), 0, math.clamp(math.random(), 0.2, 0.8), 0)
3 Likes

Thanks bro, I appreciate it <3

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Position = UDim2.new(math.random(1,10)/10, 0,math.random(1,10)/10, 0)
end)

I just saw it Here, however it didn’t work for me!