I have an error at line 26 of my code where i am trying to get a table that’s name is the player’s name. The code says “invalid argument #1 to ‘insert’ (table expected, got nil)”
Line 26
table.insert(teleportdata[v.Name], "VColonyValue = " .. v.Character.Colony.Value)
Full code
local teleportservice = game:GetService("TeleportService")
local replicatedstorage = game.ReplicatedStorage
local escapeguione = replicatedstorage:WaitForChild("EscapeGuiOne")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent.Humanoid
local colony = hit.Parent.Colony
local arrayofplayers = {
}
for i, v in pairs(game.Players:GetPlayers()) do
if v.Character:WaitForChild("Colony").Value == colony.Value and colony.Value ~= "" then
if game.ReplicatedStorage.ColonyStuff:FindFirstChild(colony.Value).MemberPermsFolder.MembersCanExit.Value == true or game.ReplicatedStorage.ColonyStuff:FindFirstChild(colony.Value).ColonyLeaderValue.Value == humanoid.Parent.Name then
table.insert(arrayofplayers, v)
teleportdata = {
}
table.insert(teleportdata, table.create(1, v.Name))
for i, v in pairs(teleportdata) do
print(v)
end
table.insert(teleportdata[v.Name], "VColonyValue = " .. v.Character.Colony.Value)
for i, v in pairs(teleportdata) do
print(v)
for e, t in pairs(teleportdata[v.Name]) do
print(t)
end
end
end
elseif v.Character.Name == hit.Parent.Name then
teleportservice:Teleport(98985454249054, game.Players:GetPlayerFromCharacter(hit.Parent))
print("teleported one player not in a colony")
end
end
local teleportoptions = Instance.new("TeleportOptions")
teleportoptions:SetTeleportData(teleportdata)
teleportservice:TeleportAsync(98985454249054, arrayofplayers, teleportoptions)
end
end)