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

How to clone a text button to a position on screen?

Asked by
zomspi 541 Moderation Voter
5 years ago
Edited 5 years ago

How do I clone a text button to a specific position on the screen? Thanks! This is my code:

local purchases = game.Players.LocalPlayer.leaderstats.Purchases
local cloned = game.ReplicatedStorage.Tools.Desert:Clone()


purchases.Changed:Connect(function()

    if purchases.Value == 1 then

        print("Hi")

        script.Parent.Visible = true
        cloned.Parent = game.Startergui.ScreenGui.Frame1
        cloned.Position - ("0.415, 0,0.116, 0")
    else

        print("Bye")

        script.Parent.Visible = false

    end

end)

4 answers

Log in to vote
1
Answered by
gloveshun 119
5 years ago

i would fixed that script :\

local purchases = game.Players.LocalPlayer.leaderstats.Purchases
local cloned = game.ReplicatedStorage.Tools.Desert:Clone()


purchases.Changed:Connect(function()

    if purchases.Value == 1 then

        print("Hi")

        script.Parent.Visible = true
        cloned.Parent = game.Startergui.ScreenGui.Frame1
        cloned.Position - UDim2.new("0.415, 0,0.116, 0")
    else

        print("Bye")

        script.Parent.Visible = false

    end

end)

Changes: UDim2.new()

Ad
Log in to vote
0
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

So first of all, I'm assuming that cloned variable is a TextButton or ImageButton in that Tools folder. So let's start.

Line 12, you set the parent. So, this cloned thing is now a child of the Frame1. So, there are questions to solve this problem.

**Is it visible? ** If it's not, then its Visible property is set to false. Its default position is the middle of the screen. So do cloned.Visible = true

**How do I move it to a certain location? ** Pretty easy. You have to change its Vector3. If it was a 3D object you had to change its CFrame but it's a Button now so cloned.Vector3 = location. You can do (example) local location = Vector3.new(1,5,6) above the cloned.Vector3, or you can do it directly, cloned.Vector3 = Vector3.new(1,5,6)

So this should work now. However you can move it like it's animated with cloned:TweenPosition() (you can also do this with frames). Hope I didn't make any mistake.

0
Vector3 is for the worldspace...UDim is for GUI's ForeverBrown 356 — 5y
Log in to vote
0
Answered by 5 years ago

Probably this:

local Text = script.Parent.TextButton

function Click()
  Text:Clone()
  Text.Position = UDim2.new(x,y,z)
end)

Text.Click:connect(Click)
Log in to vote
0
Answered by
EmK530 143
5 years ago

To gloveshun.

local purchases = game.Players.LocalPlayer.leaderstats.Purchases
local cloned = game.ReplicatedStorage.Tools.Desert:Clone()


purchases.Changed:Connect(function()

    if purchases.Value == 1 then

        print("Hi")

        script.Parent.Visible = true
        cloned.Parent = game.Startergui.ScreenGui.Frame1
        cloned.Position - UDim2.new(0.415, 0,0.116, 0)
    else

        print("Bye")

        script.Parent.Visible = false

    end

end)

Changes: UDim2.new("0.415, 0,0.116, 0") to UDim2.new(0.415, 0,0.116, 0)

You shouldn't use quotation marks because that turns it into a string.

Answer this question