I am trying to experiment with events and methods I have yet to use, and this was one of them.
I am not really sure what I did wrong with this, although. If somone could explain to me what I am missing that would be fantastic.
1 | function spawn(player) |
2 | player = game.Workspace:FindFirstChild(player.Name) |
3 | if player ~ = nil then |
4 | player:MoveTo(Vector 3. new( 1 , 1 , 1 )) |
5 | end |
6 | end |
7 |
8 | game.Players.PlayerAdded:connect(spawn) |
Thanks
EDIT: No errors are being displayed in the Output. Probably due to my if
statement protecting my script from having any errors.
EDIT2: I would prefer if you did not rewrite something entirely different. Unless you explain why my method was incorrect to even attempt.
My recommended way:
1 | game.Players.PlayerAdded:connect( function (player) --Anonymous function for when the player is added, keep an open parenthesis (bracket). |
2 | player.CharacterAdded:connect( function (char) --Anonymous function for when the player's character has been added/respawned. Keep an open parenthesis (bracket). |
3 | repeat wait() until char --Waits until the char variable is available |
4 | char:MoveTo(Vector 3. new( 1 , 1 , 1 )) --Moves the character to Vector3 point 1,1,1. |
5 | end ) --Ends character added anonymous function with a closing parenthesis to make up for the open parenthesis at line 2. |
6 | end ) --Ends player added anonymous function with a closing parenthesis to make up for the open parenthesis at line 1. |
More info:
http://wiki.roblox.com/index.php?title=Anonymous_function
What you did wrong:
You're replacing the player variable, when you can go and use the player's Character property. I also recommend linking that function to the player's CharacterAdded event in a separate function for the Player Added event.
01 | function Spawn(char) |
02 | repeat wait() until char |
03 | char:MoveTo(Vector 3. new( 1 , 1 , 1 )) |
04 | end |
05 |
06 | function PAdded(player) |
07 | player.CharacterAdded:connect(Spawn) |
08 | end |
09 |
10 | game.Players.PlayerAdded:connect(PAdded) |