Cloning TextButton doesn't appear on the screen

Hello!

I have got a bug in my local script where I clone a text button but it doesn’t appear on my screen. It does clone though.

script:

local CloneRummage = RumageFrame.RummageButton:Clone()
	CloneRummage.Parent = RumageFrame
	CloneRummage.Transparency = 0
	CloneRummage.Name = "RummageButton"
	
	local randomX = math.random(1,500)
	local randomY = math.random(1,500)
		
	CloneRummage.ZIndex = 2
	CloneRummage.Position = UDim2.new(randomX, randomY, 50, 0)
	CloneRummage.Visible = true
	
	print(CloneRummage.Position)
	
	
	CloneRummage.MouseButton1Click:Connect(function()
		CloneRummage:Destroy()
		wait(0.1)
		local newClone = CloneRummage:Clone()
		newClone.Parent = RumageFrame
	end)

What you want to do is

CloneRummage.Position = UDim2.new(0, randomX, 0, randomY)

Can’t explain that good since I’m not near my PC but if you want the buttons to appear randomly in the whole frame and not just a part of it do

local randomXOffset = math.random(0, 1)
local randomYOffset = math.random(0, 1)
 CloneRummage.Position = UDim2.new(randomXOffset, 0, randomYOffset, 0)

Check out:

for a more detailed explanation, but the overall is:
First argument is X offset, which is the offset according to its parent with a minimum of 0 and maximum of 1, so is the third but for Y. The 2nd and 4th I dont really like using but it’s a value that’s not dependent on its parent. So if u put it big enough the button will go off the screen

1 Like

Edit: Read the entire thing, first of all, you’re getting a value ranging from 1-500 to set the position, however you’re setting it on the scale, which literally means it’s getting positioned outside of the viewable screen.

I fixed it since I was putting in the values in the scale not the offset.

What I did before:

Udim2.mew(RandomX, RandomY, 50, 0)

Solutions

Udim2.mew(0, RandomX, 0, RandomY)

My roblox studio opens the start ui when opening a roblox game. Please check it out!

1 Like

hi, just wanted to provide a little bit of help / info for the UDim2 confusion:

UDim2.fromOffset(RandomX, RandomY) -- u can shorten params to avoid confusion
UDim2.fromScale(RandomX, RandomY) 
1 Like

If this is the solution to your issue, then please mark it as such, even if it’s your own reply.

Other people might find it useful later on.

Isn’t offset ranging from 0-1 and not scale? I’m pretty sure I did it correctly. And even so 500 might be too much even for scale. My suggestion was setting the offsets randomly from 0 to 1. The first thing is just an edit of OPs script

the scale ranges from 0-1 because UDim2 scale inherits lerp methods:

technically, it isn’t 0-1 because u can do 1.2 or -0.2, depending on the use-case and interface parenting

offset is the amount of pixels from the point of anchor, in which case, 0 is point of anchor for X axis, which will always be top-left corner

:slight_smile: