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.
✓ ANSWER ACCEPTED
How to make spawns that only one player can spawn at?
1 answer
✓ Accepted answer
A good way to accomplish this would be to create a function/script which does the following when fired:
- Creates a table with all spawns in it
- Starts looping through all the players
- Teleports the player to a spawn randomly selected from the table
- Removes the selected spawn from the table
- 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
This discussion is preserved as it was. New answers, comments, and votes are closed.
