Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i do cloning of TextButton and then relocating it to a random place?

I create a world for friends I created TextButton in ScreenGui I created some basic scripts in the button:

script.Parent.MouseButton1Click:Connect(function()
	--there should be a script here
end)

the purpose of the button is that when you press it, it will clone, it will go to a random place on the screen. When you press the cloned button, the same thing will do.

i tried to do this but bugs kept popping up every time.(red dot)

Does anyone know what functions should I use here? I just know that there will be Clone () and Position functions?

1 answer

✓ Accepted answer

If you have any questions then please comment them down below, the script already explains everything.

script.Parent.MouseButton1Click:Connect(function() 
	-- Change script.Parent to the textbuttons location
	
	local newButtonClone = script.Parent:Clone() -- Clones the textbutton
	newButtonClone.Position = UDim2.new(math.random(), 0, math.random(), 0) 

	-- Picks a random spot

	newButtonClone.Parent = script.Parent.Parent 
	
	-- and then parents it to the screenGui
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.