Hi! I have a teleporting script that moves players from their current position to a random choice of set positions on the map. I have recently condensed a bunch of messy if-statements to a for-loop, but now the script does not teleport. It says that it did, but nothing happened. Here is one of the for-loops that I have, plus the function that they are inside:
local function tpPlayers()
local players = game.Players:GetPlayers()
local playerSpawns = math.random(1,8)
if mapChosen == "MapOne" then
for i = 1,1,8 do
if playerSpawns == i then
players[1].Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace["MapOne"].Spawns:GetChildren()[i].Position)
end
end
end
end
If you're wondering what Spawns:GetChildren()[i] is, I have a folder with the map name on it. Inside of that, I have a folder with the name Spawns. Inside of that, I have parts with names Spawn1 through Spawn8.
If you have any questions, please feel free to ask them. I hope you can help, and if you can, thank you! :)
P.S. I will feel very stupid if I made a typo in something...
Edit: I have recently discovered that the error is coming from the fact that mapChosen is apparently not equal to any of the map names. It shows that it is in the output, but it still doesn't work.

1 comment
for loop's syntax is for init,min/max,increment so you might want to try to make it for i = 1,8,1