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 3 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 3 years ago
Edited 3 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:

math.randomseed(tick()) -- Makes math.random less predictable and more random
local spawns = {"SpawnA","SpawnB","SpawnC"} -- table of all spawns (in this example just strings)
for i,v in pairs(game.Players:GetPlayers()) do -- Loops through all the players
    local selectIndex = math.random(1,#spawns)
    -- !Insert code which teleports player to selected spawn!
    print(spawns[selectIndex],v.Name) -- Print spawn and player's name just to see that it works
    table.remove(spawns,selectindex)
end

Read more about tables here

If you have any questions feel free to ask

Ad

Answer this question