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.
function spawn(player) player = game.Workspace:FindFirstChild(player.Name) if player ~= nil then player:MoveTo(Vector3.new(1, 1, 1)) end end 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:
game.Players.PlayerAdded:connect(function(player) --Anonymous function for when the player is added, keep an open parenthesis (bracket). player.CharacterAdded:connect(function(char) --Anonymous function for when the player's character has been added/respawned. Keep an open parenthesis (bracket). repeat wait() until char --Waits until the char variable is available char:MoveTo(Vector3.new(1, 1, 1)) --Moves the character to Vector3 point 1,1,1. end) --Ends character added anonymous function with a closing parenthesis to make up for the open parenthesis at line 2. 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.
function Spawn(char) repeat wait() until char char:MoveTo(Vector3.new(1, 1, 1)) end function PAdded(player) player.CharacterAdded:connect(Spawn) end game.Players.PlayerAdded:connect(PAdded)