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

:MoveTo() not working or am I using it wrong? I am trying to move people to a spawn

local spawns = workspace.Lobby.Spawns

game.Players.PlayerAdded:connect(function(plr)
	for i,v in pairs(spawns:GetChildren()) do
		plr:MoveTo(CFrame.new(spawns[i].Position))
	end
end)

It will not move the player to the spawn.

2 answers

Edited:

You are trying to move their Player you should be moving their Character. Also you probably want to send them to a random spawn not loop through all of them. And you should get the children of the model spawns not the model itself.

local spawns = workspace.Lobby.Spawns:GetChildren() -- Assuming that Spawns is a model with parts in it.

game.Players.PlayerAdded:connect(function(player) -- When a new player joins the game do
	player.CharacterAdded:connect(function(character) -- When a players character loads do
		i = math.random(#spawns) -- Pick a Spawn
		X = spawns[i].Position.X
		Y = spawns[i].Position.Y
		Z = spawns[i].Position>Z
		character:MoveTo(Vector3.new(X, Y+4, Z)) -- Move the players character to the spawn picked
	end)
end)

5 comments

0

It doesnt work.

0

Why aren't you just using Spawns?

0

Still does not work,

0

I'm not using spawns because spawns would mess up the game

0

Just edited it

Hope this works!

local spawns = workspace.Lobby.Spawns:GetChildren()

game.Players.PlayerAdded:connect(function(plr)
    repeat wait() until plr.Character
    local Torso = plr.Character:FindFirstChild('Torso')
    if Torso then
   local SpawnChoosen = math.random(1, #spawns)
    Torso.CFrame = SpawnChoosen.CFrame
    end
end)



1 comment

0

This is just like my old example. The problem with it is that it will only move the Character once when the player first joins the game.

This discussion is preserved as it was. New answers, comments, and votes are closed.