Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make spawns that only one player can spawn at?

Asked by 4 years ago

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.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

A good way to accomplish this would be to create a function/script which does the following when fired:

  1. Creates a table with all spawns in it
  2. Starts looping through all the players
  3. Teleports the player to a spawn randomly selected from the table
  4. Removes the selected spawn from the table
  5. Continues loop until all players have been looped through

Pseudo-example:

1math.randomseed(tick()) -- Makes math.random less predictable and more random
2local spawns = {"SpawnA","SpawnB","SpawnC"} -- table of all spawns (in this example just strings)
3for 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)
8end

Read more about tables here

If you have any questions feel free to ask

Ad

Answer this question