Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question