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 » Scripters
Home Search
 

Detect player by name on join

Previous Thread :: Next Thread 
loterman23 is online. loterman23
Joined: 06 Apr 2008
Total Posts: 178
30 Oct 2015 12:55 AM
I'm trying to detect specific players by name upon joining the world, but for some reason this wants to keep coming back as no success.

name = game.Players

if name == "Player" then
print("Success!")
else
print("No Success")
end
Report Abuse
Ben1925 is not online. Ben1925
Joined: 07 Apr 2011
Total Posts: 741
30 Oct 2015 01:01 AM

function onPlayerAdded(player)
if player.Name == "Player" then
print("Success!")
else
print("failed!")
end

game.Players.PlayerAdded:connect(onPlayerAdded)
Report Abuse
loterman23 is online. loterman23
Joined: 06 Apr 2008
Total Posts: 178
30 Oct 2015 01:04 AM
So.. statements always have to be in functions? I'm pretty much learning as I go.
Report Abuse
Ben1925 is not online. Ben1925
Joined: 07 Apr 2011
Total Posts: 741
30 Oct 2015 01:06 AM
Not necessarily. Functions are there if you want certain lines of code to be reused, so you don't have to copy and paste over and over again.

A function is defined there because that line of code you're going to use will have to be used over and over again.

There's a connection line on the very bottom (game.Players.PlayerAdded:connect(onPlayerAdded))

That runs the function every time a Player joins.
Report Abuse
loterman23 is online. loterman23
Joined: 06 Apr 2008
Total Posts: 178
30 Oct 2015 01:10 AM
Actually, yours doesn't seem to be working at all, what I have just outputs no success, even though there is a Player named "Player" in the game.
Report Abuse
championbuilder is not online. championbuilder
Joined: 20 Jan 2009
Total Posts: 13544
30 Oct 2015 01:13 AM
^ Add an extra end to his script and it will work
Report Abuse
Ben1925 is not online. Ben1925
Joined: 07 Apr 2011
Total Posts: 741
30 Oct 2015 01:14 AM
Oh, yeah, sorry. Forgot to put an end lol
Report Abuse
loterman23 is online. loterman23
Joined: 06 Apr 2008
Total Posts: 178
30 Oct 2015 01:16 AM
Yeah, I noticed that as well, and put it in before I tested it.
Report Abuse
Ben1925 is not online. Ben1925
Joined: 07 Apr 2011
Total Posts: 741
30 Oct 2015 01:18 AM
Sometimes when you join Studio, you may join as Player1 or simply Player. It works fine for me, printing "Success" on my join. Maybe you joined as Player1?
Report Abuse
loterman23 is online. loterman23
Joined: 06 Apr 2008
Total Posts: 178
30 Oct 2015 01:20 AM
It's got me joinned as Player, but even if I try Player1, no luck, the code is the same?

function onPlayerAdded(player)
if player.Name == "Player1" then
print("Success!")
else
print("failed!")
end

game.Players.PlayerAdded:connect(onPlayerAdded)
end
Report Abuse
Ben1925 is not online. Ben1925
Joined: 07 Apr 2011
Total Posts: 741
30 Oct 2015 01:22 AM
Oh no, You don't add the end after the connection line, that won't work.

You have to add it after you've closed the function.
Report Abuse
loterman23 is online. loterman23
Joined: 06 Apr 2008
Total Posts: 178
30 Oct 2015 01:24 AM
I... thought that looked different, my god, I need sleep
Report Abuse
Ben1925 is not online. Ben1925
Joined: 07 Apr 2011
Total Posts: 741
30 Oct 2015 01:35 AM
lol
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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