Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isnt this spawn script working?

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)

3 answers

✓ Accepted answer

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)

1 comment

0

Still wrong, read my answer in order to understand why this is wrong, you were off just slightly.

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)

2 comments

0

That does not work. MoveTo is not a valid member of Player

0

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.