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

Player name script efficiency help?

Asked by
TrollD3 105
9 years ago

I made a script to get player names when they enter the game. Its not working but I wanted to make it more efficient but Im stuck. Original script:

local lobby = game.StarterGui.MainGui.MenuButton.Lobby
game.Players.PlayerAdded:connect(function(player)
    local ch = game.Players:GetPlayers()
    for i = 1, #ch do
        lobby["Player" .. i].Text = ch[i].Name
    end
    for i = #ch + 1, 16 do --clear the unused TextLabels
        lobby["Player" .. i].Text = ""
    end
end)

New script : I was trying to make this script put the player's name inside a txt button and also the names would be evenly spaced.

local Player3 = script.Parent.Base:clone()
    Player3.Position = Player3.Position + UDim2.new(0,0,0,Players2*29)
    Player3.Visible = true
    Player3.Parent = script.Parent
    Player3.Name = "Player"
    Player3.Text = v.Name

1 answer

Log in to vote
1
Answered by 9 years ago

Why are you changing StarterGui in the first script? Why are you clearing the text labels after you set them?

local Container = script.Parent
local Base = script.Base:Clone()
local Padding = 0.05

function Update()
    for o,Player in ipairs(Game.Players:GetPlayers())
        local Element = Base:Clone()
        Element.Text = Player.Name  
        Element.Position = UDim2.new(0,0,0,((o-1)*Element.Size.Y.Scale)+Padding)
        Element.Parent = Container
    end
end

Game.Players.Changed:connect(function(d)
    if d =="NumPlayers" then
        Update()
    end
end)
0
btw the script is referring to base inside the frame. I tried editing it and its still not working. TrollD3 105 — 9y
Ad

Answer this question