When the player joins, I want them to teleport to a spot in the game. Why doesn't this script work?
function onPlayerAdded(player)
game.Players.Player:MoveTo =(Vector3.new(20.755, 28.28, -218.88))
end
game.Players.PlayerAdded:connect(onPlayerAdded)
When the player joins, I want them to teleport to a spot in the game. Why doesn't this script work?
function onPlayerAdded(player)
game.Players.Player:MoveTo =(Vector3.new(20.755, 28.28, -218.88))
end
game.Players.PlayerAdded:connect(onPlayerAdded)
Well :MoveTo is not a valid member of player, so this is how we are going to do it. first we will start out with the function however I think it would be easier to use an anonymous function.
game.Players.PlayerAdded:connect(function(plr)
end)
now that we have the function down we should move on to what this function Does so you are wanting to move a player on spawn to that Position but you can't move a Player, as it is not what is Inside of Workspace the thing that players use are Characters so while we no longer need to use the game.Players.plr.Character any longer we can just use plr.Character and that should work
game.Players.PlayerAdded:connect(function(plr)
plr.Character:MoveTo(Vector3.new(20.755, 28.28, -218.88))
end)
but I would much prefer myself using a CFrame on the Plrs Torso. so here is MY Method on doing it..
game.Players.PlayerAdded:connect(function(plr)
local tor = plr.Character:findFirstChild("Torso")
if tor then
tor.CFrame = CFrame.new(20.755, 28.28, -218.88)
end
end)
Don't have to do it that way but it should work much simpler.
function onPlayerAdded(player)
game.Players.Player:MoveTo(Vector3.new(20.755, 28.28, -218.88)) --Not entirely sure, but I think your '=' was the problem
end
game.Players.PlayerAdded:connect(onPlayerAdded)
You dont need the equals sign. Heres how it should be
function onPlayerAdded(player)
game.Players.Player:MoveTo(Vector3.new(20.755, 28.28, -218.88))
end
game.Players.PlayerAdded:connect(onPlayerAdded)
That does not work. MoveTo is not a valid member of Player
Close, but :MoveTo like JohnTUnderwood said, is not a valid member of player, meaning you can't use :MoveTo on Players that are within game.Players
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Still wrong, read my answer in order to understand why this is wrong, you were off just slightly.