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

How would I make label(s) in different positions depending on how many values?

Asked by
Qorm 100
9 years ago

Basically I made a door which opens to whoever owns the tycoon, and I made a ScreenGui to basically add users to the door so it can open for them! Well, I did everything else except the TextLabel part.. I want to acknowledge how to space out the position (y) in my ScrollingFrame. I looked for it at a lot of places and found no results. This is the script without the part explained above:

script.Parent.MouseButton1Click:connect(function()
    if game.Players:FindFirstChild(script.Parent.Parent.username.Text) then
        if not game.Workspace.Tycoon1:findFirstChild("door").friends:FindFirstChild(script.Parent.Parent.username.Text) then
    local n=Instance.new("StringValue",game.Workspace.Tycoon1:findFirstChild("door").friends)
    n.Name=script.Parent.Parent.username.Text
    local c=Instance.new("TextLabel",script.Parent.Parent.friends)
--heres the part i really need help with--
    c.Name=n.Name
    c.Text=n.Name
    c.Size=UDim2.new(1,0,.1,0)
------------------------------------------------
    else
        return
        end
        end
end)

Help on this would be appreciated and just comment below if you need some additional information because I'm pretty bad at explaining things in my perspective lol

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

First, let's do a little code clean up.

First: Tab your code correctly.

Next: You can say workspace instead of game.Workspace, so let's use that to be briefer.

You use script.Parent 5 times -- so it would be worth it to use a variable for it instead. I called it button. We still use button.Parent four times. Three times it's for button.Parent.username.Text, so that should definitely be a variable. (We can also use it instead of n.Name)

There's no point for the else return since nothing happens after that point, anyway.


local button = script.Parent

button.MouseButton1Click:connect(function()
    local name = button.Parent.username.Text
    if game.Players:FindFirstChild(name) then
        if (not workspace.Tycoon1["door"].friends:FindFirstChild(name)) then
            local n = Instance.new("StringValue", workspace.Tycoon1["door"].friends)
            n.Name = name
            local c = Instance.new("TextLabel", button.Parent.friends)
            c.Name = name
            c.Text = name
            c.Size = UDim2.new(1, 0, .1, 0)
        end
    end
end)

Now we just need to set the Position of c.

Since each is .1 tall, we could place each one at y = 0.1 * #of_things_in_frame:

        local others = button.Parent.friends:GetChildren()
        c.Position = UDim2.new(0, 0, 0.1 * (#others - 1), 0)

(or some variation of this). This is the simplest way to accomplish this.

Ad

Answer this question