Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Player name script efficiency help?

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

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)

1 comment

0

btw the script is referring to base inside the frame. I tried editing it and its still not working.

This discussion is preserved as it was. New answers, comments, and votes are closed.