|
| 25 Jul 2014 01:28 AM |
So, I'm trying to put players into global strings, but I just can't understand one part of the wiki's code. Can someone describe this section? .. player.Name
game.Players.PlayerAdded:connect(function(player) print("A player has entered: " .. player.Name) end)
|
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Jul 2014 01:34 AM |
game.Players.PlayerAdded:connect(function(player) -stuff end)
The above code activates when a player joins the game. It has an argument (here we called it player) that gives you the player Instance ready to play with.
Here's something that will make a string out of all of the player's names and print them out (each seperated by "|") whenever a player leaves/joins:
function makeList() playerString = "|" for _, v in pairs(game.Players:GetChildren()) do playerString = playerString..v.Name.."|" end return (playerString.."|") end
game.Players.PlayerAdded:connect(function() print(makeList()) end)
game.Players.PlayerLeaving:connect(function() print(makeList()) end)
【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】 |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 Jul 2014 01:35 AM |
'game.Players.PlayerAdded:connect(function(player) print("A player has entered: " .. player.Name) end)'
add an event listener: every time a Player is added, run the function below. The PlayerAdded event automatically gives you the new player. The .. means "join" ("a" .. "b" = "ab") and player.Name is the Name of the player (a property of basically all instances) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 Jul 2014 01:35 AM |
| run the function that is in the first argument* |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 01:37 AM |
game.Players.PlayerAdded:connect(function(player)--This gets the player when they join the game. print("A player has entered: " .. player.Name)--When this is printing it is getting player.Name so it is getting the player who entered the game's name and will print: A player has entered: Player1, if you use it in studio. end)--The end is with a ) cause it this isn't a normal function.
Normal function this might be easier to use if you're new to scripting.
function PlayerJoined(p)--PlayerJoined can be called what ever you want. --Code run's here print(p.Name..' has entered the game.') --You can aslo print stuff like this if it doesn't include code. print'Hello!' end--This is a end for the function
--but cause this has been changed you a connection line to fire the function. game.Players.PlayerAdded:connect(PlayerJoined) |
|
|
| Report Abuse |
|
|