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

Help with spawning in the correct sequence?

Asked by
waifuSZN 123
8 years ago

I have 15 spawns in my game, each named "1" through "15", respectively, stored in a Folders object named SpawnLocations.

This is the corresponding code:

local REQUIRED_PLAYERS = 1

game.Players.PlayerAdded:Connect(function(player)

01for n, player in pairs(game.Players:GetPlayers()) do
02    local playerTable = {}
03    local n = 1
04 
05    playerTable[n] = player
06    n = n + 1
07    end
08 
09if game.Players.NumPlayers == REQUIRED_PLAYERS then
10    for n = 1, 1 do
11        player:LoadCharacter()
12        player.Character.PrimaryPart.Position = game.Workspace.SpawnLocations[tostring(n)].Position
13    end
14end

end)

The problem that arises, is that when I go to test this via server, the player joins, but spawns at spawn #6, instead of spawn #1. Also, his head falls off.

I am unsure where the code in incorrect, but I'm willing to hear all suggestions.

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

You didn't describe exactly what the code is supposed to do, so I made a guess:

01local Players = game:GetService("Players")
02local SpawnLocations = workspace.SpawnLocations
03local i = 1
04 
05Players.CharacterAutoLoads = false
06 
07Players.PlayerAdded:Connect(function(Player)
08    Player.RespawnLocation = SpawnLocations[i] -- Assign new Player to a Spawn
09    i = i + 1
10    Player:LoadCharacter()
11end)
0
Thank you for this answer. Works as I wanted it to. I must have overthought the spawning process, you made it look so simple. Thanks again. waifuSZN 123 — 8y
0
Yup! No problem. Roblox has a lot of things built-in to make life easier! And for things that aren't built-in, I've written some modules for those. Let me know if you need any more help! Add me on Discord: Niles#8328 Validark 1580 — 8y
0
You also might want to make an adaptive system that accounts for when players leave the game, and a new one takes their place. The simple version I wrote for you only accounts for players entering and staying in the game. Send me your finalized code when you've completed it! Validark 1580 — 8y
Ad

Answer this question