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

Displaying A Player list on a text button?

Asked by 10 years ago

Displaying A Player list on a text button I want to make a bunch of text buttons displaying player names. All though this doesnt work if it worked would it be efficient? If not how could I make it?

player = game.Players.NumPlayers
playerRand = math.random(1, #player)
script.Parent.Text = playerRand.Name

1 answer

Log in to vote
0
Answered by 10 years ago

No. This would not be efficient at ALL. You would have many copies of the same name. You should use this:

-- BEFORE YOU DO ANYTHING, CREATE SLOTS NUMBERED 1 - 8 -- CHANGE 8 TO MAX PLAYERS
player = game.Players.LocalPlayer
players = game.Players:GetChildren()
repeat wait() until player.Character
plrn = 1

for i, v in pairs(players) do
    slot = script.Parent.Parent:FindFirstChild(plrn)-- LOCATION OF SLOT
    slot.Text = v.Name
    slot.MouseButton1Click:connect(function()
        chosenPlayer = game.workspace:FindFirstChild(slot.Text)
        if chosenPlayer then
            -- SCRIPT THAT DOES STUFF TO PLAYER
        end
    plrn = plrn + 1
    end)
end
Ad

Answer this question