I Want players in a table to teleport in a specific position. But, the output says that HumanoidRootPart Is Nil.
And I have made a table and saw,
[1] = Brioche_Noodle [2] = "*** cycle table reference detected ***"
Function That I am focusing on,
function spawnMap()
local Maps = Storage.Maps:GetChildren()
chosenMap = Maps[math.random(1, #Maps)]
chosenMap:Clone()
chosenMap.Parent = workspace.Map
for _, player in ipairs(Playing) do
if player then
print(player)
player.Character.HumanoidRootPart.Position = Vector3.new(chosenMap.Teleporter.Position)
end
end
end
Here is my whole script.
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local Storage = game:GetService("ServerStorage")
local Playing = {}
local NotPlaying = {}
local Infected = {}
local Team = {
Lobby = Teams.Lobby,
Infected = Teams.Infected,
Citizens = Teams.Citizens
}
local gameStarted = false
local chosenMap
local function onPlayerAdded(player)
print(player.Name .. " || Joined || ")
if gameStarted == false then
print(player.Name .. " is added to The Playing Table")
table.insert(Playing, player)
print(Playing)
else
print(player.Name .. " is added to The Not Playing Table")
table.insert(NotPlaying, player)
print(NotPlaying)
end
player.Team = Team.Lobby
end
local function addPlayerToPlaying()
local AllPlayers = Players:GetPlayers()
table.insert(Playing, Playing)
end
local function addPlayerToNotPlaying()
local AllPlayers = Players:GetPlayers()
table.insert(NotPlaying, Playing)
end
function spawnMap()
local Maps = Storage.Maps:GetChildren()
chosenMap = Maps[math.random(1, #Maps)]
chosenMap:Clone()
chosenMap.Parent = workspace.Map
for _, player in ipairs(Playing) do
if player then
print(player)
player.Character.HumanoidRootPart.Position = Vector3.new(chosenMap.Teleporter.Position)
end
end
end
function despawnMap()
local Maps = Storage.Maps:GetChildren()
chosenMap.Parent = nil
for _, player in ipairs(Playing) do
if player then
player.CharacterAdded:Connect(function(Character)
Character.HumanoidRootPart.Position = Vector3.new(chosenMap.Lobby.Teleporter.Position)
end)
end
end
end
-- Listeners
Players.PlayerAdded:Connect(onPlayerAdded)
-- Script
while true do
gameStarted = false
wait(4)
gameStarted = true
addPlayerToPlaying()
spawnMap()
wait(10)
despawnMap()
Playing = nil
NotPlaying = nil
Infected = nil
end

3 comments
addPlayerToPlaying/NotPlaying does not do as their title says. Why are you inserting the Playing array?
FYI, line 57/70 is redundant.
despawnMap fails to live up to its title, too