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

Textlabel getting moved each time a new one spawns?

Asked by
iNicklas 215 Moderation Voter
8 years ago

Okay so i have this, custom ingame leaderboard.

Everytime i player joins it creates a textlabel, but i want the textlabel to move

{0, 0},{0.05, 0} each time a new one comes, so it isnt overlayed

CODE

game.Players.PlayerAdded:connect(function(player)

local label = Instance.new("TextLabel",script.Parent.SurfaceGui.Frame)

label.BorderSizePixel = 0
label.BackgroundTransparency = 1
label.Size = UDim2.new(1, 0, .05, 0)
label.Font = "ArialBold"
label.FontSize = "Size36"
label.TextColor3 = BrickColor.White().Color
label.TextStrokeTransparency = 0.5
label.Text = player.Name.." - "..player.userId

end)

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Well, I see no attempt of you trying to push its position down. What you need to do is set a variable, that would contain the last TextLabel, or its position. So:

LastLabel = nil

game.Players.PlayerAdded:connect(function(player)
    local label = Instance.new("TextLabel",script.Parent.SurfaceGui.Frame)
    label.BorderSizePixel = 0
    label.BackgroundTransparency = 1
    label.Size = UDim2.new(1, 0, .05, 0)
    label.Font = "ArialBold"
    label.FontSize = "Size36"
    label.TextColor3 = BrickColor.White().Color
    label.TextStrokeTransparency = 0.5
    label.Text = player.Name.." - "..player.userId
    if LastLabel ~= nil then
        label.Position = LastLabel.Position + UDim2.new(0, 0, .05, 0)
    end
    LastLabel = label
end)

game.Players.PlayerRemoving:connect(function(player)
    if script.Parent.SurfaceGui.Frame:findFirstChild(player.Name.." - "..player.userId) then
        script.Parent.SurfaceGui.Frame['player.Name.." - "..player.userId']:Destroy()
    end
end)
Ad

Answer this question