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)

2 comments
Thank you. I'm pretty new to table functions
No problem! Just takes some practice.