Random spawns not being random?

I have no clue how to do that… :confused:

Replace ‘organizeTeams’ and ‘getRandomSpawn’ and ‘teleportPlayer’ with this:

function teleportPlayer(player, i)
	if player then
		local character = player.Character
		if character then
		local selectedSpawn = getSpawn(player.Team, i)
        end
    end
end


function getSpawn(team, i)
	if gameMap then
		local spawns = {}
		if team == teams.Red then
			spawns = gameMap.Spawns.Taggers:GetChildren()
		else
			spawns = gameMap.Spawns.Runners:GetChildren()
		end
		local spawn = spawns[i]
		return spawn
	end
	return nil
end

function organizeTeams()
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			teleportPlayer(player, i)
        	end
	end
end

Something else that may work is to put a wait() between each ‘teleportPlayer(player)’ in your original code.

Also, if you call ‘getRandomSpawn’ anywhere else in your script, rename ‘getSpawn’ to ‘getRandomSpawn’ and make sure to add the integer parameter every time you call it.

I also just noticed it seems like you have two functions which are called exactly the same thing?

Or you’ve edited the code since posting originally?

Oh no, i had only copied the relevant stuff when i made the post. I thought the rrest would be unneccesary

Oh, I see.

If you’re not using these functions elsewhere, you might want to consider just putting it all in one core ‘TeleportPlayers’ function which takes all of the players as a parameter, and then spawns them using a for loop like the one in my earlier reply.

I’ve had the new Random stuff solve some unpleasant patterning I experienced with math.random.

In the future, never use math.random, the alternative is far, far superior and will save you headaches.

2 Likes