Its Not Teleporting Players To Map Spawns

So im making a intermission. So far I have it working ACCEPT the code breaks when it gets to teleporting players. I have custom spawns in the map model. But for some reason between line 27 31 its not teleporting the player. It says the problem is line 30 with the CFrame. Please tell me what im doing wrong this has taken me so long to figure out

2 Likes

spawns is a table variable, do spawns[num]

2 Likes

CFrame.new(spawns[num].Position)

1 Like

I would recommend you tp the HumanoidRootPart instead of the head. As well as do what the person above me said.

1 Like

Instead of using

for i = 1 #plrs do

Use:

for i, v in pairs(plrs) do

i, the first value, is the index, while v, the second value, returns the object corresponding to the index.


I would also recommend you to use :SetPrimaryPartCFrame() and the HumanoidRootPart(the character models primary part):

CharacterModel:SetPrimaryPartCFrame(spawn.Positioin)

__
In addition, the reason it errors is because of this line:

local spawns = currentMap:WaitForChild(MapName.Value).Spawns:GetChildren()

Because you are trying to define one spawn on this line

plr[i].Character.Head.CFrame = CFrame.new(spawns.Position) -- the, "spawns" variable is an array, not a position

This problem can be fixed like this

plr[i].Character.Head.CFrame = CFrame.new(spawns[num].Position)

Your final code would look something like this:

for i, player in pairs(plrs) do -- if (plrs) errors, try (plrs:GetPlayers())
    local spawns = currentMap:WaitForChild(MapName.Value).Spawns:GetChildren()
    local num = math.random(1, #spawns)
    v.Character:SetPrimaryPartCFrame(spawns[num].Position)
end

Please copy and paste code next time, because it is tedious to type it in.


@LoveTheBears101 Please don’t repeat posts, and your second solution

Wouldn’t work.

1 Like
  1. You should do:
    plrs[i].Character.UpperTorso.CFrame = spawns[num].CFrame because spawns is a table
  2. If that doesn’t work, make sure plrs is a list of players
2 Likes
  1. I didn’t see the other post, I was trying to be helpful by point out that spawns was a list.
  2. Yes, making sure the list of plrs is a list of players would work because if plrs is wasn’t a list of the players, it wouldn’t work
2 Likes