Help me on this code about tables

Hi, I’m trying to teleport a player to a brick that the value of is in a table but Idk how here is the code
> local spawnpoints = cloneMap:FindFirstChild(“Spawnpoints”)

    	local availableSpawnpoints = spawnpoints:GetChildren()
    	availableSpawnpoints = availableSpawnpoints
    	for i, player in pairs(players) do
    		if player then
    			local character = player.Character
    			if character then
    				character:FindFirstChild("HumanoidRootPart").CFrame = availableSpawnpoints[1].CFrame
    				table.remove(availableSpawnpoints, 1)

This doesn’t make sense at all. What you’ll need to do is a for loop and add the objects into a table

1 Like

It’s cus I tried messing around a bit with it and forgot to remove it and I thought the “GetChildren()” function made it into a table automatically

Nope. You’ll need to do a for loop for each object and insert it into the table. Make sure you insert the name, not the instance!

1 Like

Ok, Thank you! I will try it out in a bit and let you know how it goes.

You don’t need to do if player in this case. When iterating over a table with pairs or ipairs you’ll never have a nil key or value.

Also, if it’s an array, ipairs is the correct iterator to use.

3 Likes

I have never looped through an array using ipairs.

if GetChildren() doesn’t return a table what does it return?

I think it returns nil cus the error says "Cannot link CFrame with nil or something like that