Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Scrxptss -13
7 years ago
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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)
0
It doesnt work. Scrxptss -13 — 7y
0
Why aren't you just using Spawns? shadownetwork 233 — 7y
0
Still does not work, Scrxptss -13 — 7y
0
I'm not using spawns because spawns would mess up the game Scrxptss -13 — 7y
0
Just edited it shadownetwork 233 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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)



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. shadownetwork 233 — 7y

Answer this question