I'm trying to make a spawn system where only one player can spawn at every spawn, and I've made a few systems, but the scripting always gets huge, out of control, and doesn't work. It's kind of like the lobby system in literally any battle royale game. I can't offer much more, so, thanks for any help.
A good way to accomplish this would be to create a function/script which does the following when fired:
Pseudo-example:
1 | math.randomseed(tick()) -- Makes math.random less predictable and more random |
2 | local spawns = { "SpawnA" , "SpawnB" , "SpawnC" } -- table of all spawns (in this example just strings) |
3 | for i,v in pairs (game.Players:GetPlayers()) do -- Loops through all the players |
4 | local selectIndex = math.random( 1 ,#spawns) |
5 | -- !Insert code which teleports player to selected spawn! |
6 | print (spawns [ selectIndex ] ,v.Name) -- Print spawn and player's name just to see that it works |
7 | table.remove(spawns,selectindex) |
8 | end |
Read more about tables here
If you have any questions feel free to ask