I made a script that chooses a random number between 1 and the amount of spawn points, but I can't get the player's Torso to move to the place I want. Any help?
Here's the script :
local button = script.Parent.spawnButton local blackScreen = script.Parent.Parent.blackScreen local spawned = game.Players.LocalPlayer.data.spawned local humanoid = game.Players.LocalPlayer.Character.Humanoid local spawns = {} for i, v in pairs(workspace.spawnPoints:GetChildren()) do table.insert(spawns, i) print("[SpawnCheck] Spawn " .. i .. " ready") wait() end button.MouseButton1Down:connect(function() for i = 1, 20 do blackScreen.BackgroundTransparency = blackScreen.BackgroundTransparency - .05 wait(.025) end print("[SpawnCheck] Teleport started") local n = math.random(#spawns) humanoid.Parent.Torso.CFrame = CFrame.new(spawns[n].Position) print("[SpawnCheck] Teleport finished") end)
The error message I get in the output is exactly this : 10:43:09.838 - Players.Player1.PlayerGui.main.rightSide.spawnHandler:20: attempt to index field '?' (a number value)
Line 8:
table.insert(spawns, i)
That's incorrect. You're inserting the *index *into the table. You want to insert the value of that index, which is "v" in this case. Change that line to:
table.insert(spawns, v)