for i,v in pairs(game.Workspace:GetDescendants()) do
if v.Name == "Spawnpoint" then
local choice = v:GetChildren()
local ChosenSpawn = choice[math.random(0, #choice)]
wait()
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame
end
end
I'm trying to make a script that finds all parts called "Spawnpoint" and then picks a random one, then teleports the player to it. I was getting errors when I did
choice[math.random(1, #choice)]
bad argument #2 to 'random' (interval is empty)
I don't know if I've fixed it but now I keep getting this error:
attempt to index local 'ChosenSpawn' (a nil value)
Can anyone help me?

2 comments
bad argument #1 to 'insert' (table expected, got nil) The script teleports me to only one part, none of the others, any way to fix?
Ah. line 8 should be "choices = {}"