I'm trying to make a teleport script that teleports every player onto the map that was chosen but it only teleports either the players or the beast (another table in my game). The script looks like this and I can't figure the error out for the life of me:
_G.Players = {} _G.Beast = {} local PlayersToChooseFrom = {} for i, v in pairs(game.Players:GetPlayers()) do table.insert(PlayersToChooseFrom, v.Name) end -- The map is loaded in here but thats not important, as it already works. local chosenBeast = math.random(1, #PlayersToChooseFrom) for i, v in pairs(PlayersToChooseFrom) do if i == chosenBeast then table.insert(_G.Beast, PlayersToChooseFrom[i]) table.remove(PlayersToChooseFrom, i) workspace[_G.Beast[1]].HumanoidRootPart.CFrame = CFrame.new(workspace.MapStorage.Map.BeastSpawn.Position) else table.insert(_G.Players, PlayersToChooseFrom[i]) table.remove(PlayersToChooseFrom, i) end end -- Below is what doesn't work, but also doesn't error out for i, v in pairs(_G.Players) do local spawns = workspace.MapStorage.Map.Spawns:GetChildren() workspace[v].HumanoidRootPart.CFrame = CFrame.new(spawns[i].Position) end
Thanks in advance for figuring this out. All of the words are spelled correctly (I know because it doesn't error out for me defining nil values).
-Cmgtotalyawesome