"Table index is nil."

I keep on getting Table index is nil.

local ServersCreated = {
	["ServerIndex"] = {}
}

local CurrServers = 0

function game.ReplicatedStorage.Remotes.CreateServer.OnServerInvoke(plr, CreationData)
	if not table.find(ServersCreated, CreationData[1]) then
		local code = game:GetService("TeleportService"):ReserveServer(13414792758)
		CurrServers += 1
		local mugroobeer={Display=CreationData[1],Region=CreationData[2],Server=code,ServerID=CurrServers}
		table.insert(ServersCreated["ServerIndex"], mugroobeer)
		ServersCreated["ServerIndex"][CreationData[1]] = ServersCreated["ServerIndex"][1]
		ServersCreated["ServerIndex"][1] = nil
		for _, player in pairs(game:GetService("Players"):GetPlayers()) do
			local Template = script.Template:Clone()
			Template.ImageLabel.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..CreationData[3].."&width=420&height=420&format=png"
			Template.Region.Text = CreationData[2]
			Template.ServerName.Text = CreationData[1]
			Template.Play.MouseButton1Click:Connect(function()
				if game.PlaceId == 13414792758 then
					game:GetService("TeleportService"):TeleportToPrivateServer(13392833049, ServersCreated["ServerIndex"][ServerData[1]][3], {player})
				else
					game:GetService("TeleportService"):TeleportToPrivateServer(13414792758, ServersCreated["ServerIndex"][ServerData[1]][3], {player})
				end
			end)
			Template.Name = CreationData[1]
			Template.Parent = player.PlayerGui.Main.ServerList.ScrollingFrame
		end
	end
end

Anyone know why this keeps happening?

What is the error? Where does it take you?

Table index is nil. Line 264. Right after the table.insert().

Might be because it’s nil, try setting it to something

What do you mean its nil? It’s clearly defined here:

local ServersCreated = {
	["ServerIndex"] = {}
}

But ServerIndex is nil, it doesn’t have anything in it

It’s nil? I’m pretty sure nil mean’s it doesn’t exist. {} is declaring a new table.

And the Table doesn’t have anything in it, and you’re trying to index something in it (which doesn’t exist) thus making it nil

I inserted a table inside it if you didn’t see.

table.insert(ServersCreated["ServerIndex"], mugroobeer)

Also,

local mugroobeer={Display=CreationData[1],Region=CreationData[2],Server=code,ServerID=CurrServers}

Check if moogroober actually exists before running the rest

1 Like

I was right, just my arguments were off, I did 1, 2, 3 instead of Display, etc.
I changed back my arguments to 1, 2 ,3 then fired, it worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.