Math.random printing out everything

hello, so i have this line of code that is suppose to print a random part called “SpawnPoint” but its printing out every part thats called “SpawnPoint”

Feel free to ask any questions

1 Like

The code is doing its job correctly if it prints out every possible spawn point. You are iterating upon a table meaning after it has finished one cycle it will repeat itself until it has iterated upon each player.

3 Likes

Maybe try to do it outside of the loop?

local chosenSpawn = spawns[math.random(1,#spawns)]
print(chosenSpawn)
for i,v in pairs (game.Players:GetPlayers()) do
v.Character.HumanoidRootPart.CFrame = chosenSpawn.CFrame
end