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

Get A Single Player's Name?

Asked by 9 years ago

The following script gets all the player's names once the script's parent (Part) is touched.

local debounce = false

script.Parent.Touched:connect(function(hit)

    if not debounce then

        debounce = true

        local list = {}

        for i, plr in pairs(game.Players:GetPlayers()) do

            table.insert(list, plr.Name)

            msg = Instance.new("Message")
            msg.Parent = game.Workspace
            msg.Text = table.concat(list, "")

        end

        debounce = false

    end

end)

What would I need to do to this script to only get 1 player's name instead of them all?

0
Don't search through the players, check if hit.Parent is a humanoid, then use the :GetPlayerFromCharacter() method. GoldenPhysics 474 — 9y
0
This script is going to be for a leaderboard that is displayed in a GUI at the end of the game. I only used the onTouched() function to test it. I know what you're saying, though. alienantics 15 — 9y

1 answer

Log in to vote
0
Answered by
Tesouro 407 Moderation Voter
9 years ago

You don't need to create a table, GetPlayers already return a table. Also, that debounce is useless, because it has no wait.

local debounce = false

script.Parent.Touched:connect(function(hit)

    if not debounce then

        debounce = true

       local list = game.Players:GetPlayers())

       msg = Instance.new("Message")
       msg.Parent = game.Workspace
       msg.Text = table.concat(list, "")

        wait(1) -- the debounce wait

        debounce = false

    end

end)
Ad

Answer this question