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

How do I get a player's name when the player joins the game?

Asked by
RGRage 45
7 years ago

I have been trying to find a way to make a part follow a specific person when they get close, but I can't find out a way to get the person's name and tell the part which person to go towards without making a script with the specific person's name in it. Can someone help me?

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Use a PlayerAdded event!

Using the Players Service, we can tell when a player joins the game and get that specific player. Example,

-- Regular script
game.Players.PlayerAdded:connect(function(plr)
    print(plr.Name)-- Prints players' names
end)
Your question didn't say much about the follow brick thing, and you should try doing that yourself before posting another question.

How do I get the character?

This is what I think you meant. We can use the CharacterAdded event of the player we got from the PlayerAdded event. Example,

-- Regular script
game.Players.PlayerAdded:connect(function(plr)-- Gets the player
    plr.CharacterAdded:connect(function(char)-- Gets the character
        local Torso = char:WaitForChild("Torso")-- Gets the torso
    end)
end)
I also got the Torso defined for you so you can make that follow brick!

Good Luck!

If I helped, please don't forget to accept my answer.
Ad

Answer this question