generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Saving Players into Global Strings

Previous Thread :: Next Thread 
madkaratemans is not online. madkaratemans
Joined: 28 Dec 2010
Total Posts: 12
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
neontails190 is not online. neontails190
Joined: 21 Aug 2012
Total Posts: 290
25 Jul 2014 01:29 AM
lol

/e dance2
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
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 is not online. 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 is not online. 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
4444vince2 is not online. 4444vince2
Joined: 08 Nov 2008
Total Posts: 4880
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image