|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 30 Oct 2015 01:13 AM |
| ^ Add an extra end to his script and it will work |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 30 Oct 2015 01:16 AM |
| Yeah, I noticed that as well, and put it in before I tested it. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 30 Oct 2015 01:24 AM |
| I... thought that looked different, my god, I need sleep |
|
|
| Report Abuse |
|
|
Ben1925
|
  |
| Joined: 07 Apr 2011 |
| Total Posts: 741 |
|
| |
|