How to make a randomized spawn system? (Solved)

So I’m trying to create a spawn system like Zo using spawn locations and tables. When a player first loads in they’re added to a LobbyTable meaning they can only spawn on spawn locations named LobbySpawn. Then when a player touches a specific part they’re removed from the LobbyTable and added to the BattlegroundTable. While in this table they’ll only spawn at spawn locations named BattlegroundsSpawn.

I’ve tried multiple methods for trying to do this but to no avail. Any suggestions or ideas on how to execute this is much appreciated!

2 Likes

A bit unclear, do you want suggestions or do you want me to provide you a script?

1 Like

Suggestions, lmk how I can explain it better if it’s unclear!

1 Like

Pretty much we have 2 tables and 2 sets of spawn locations. 1 table is named LobbyTable, the other is named BattlegroundsTable. 1 set of spawn locations is named LobbySpawn, while the others are named BattlegroundsSpawn. I want it so if a player is in the lobby table then they’ll only spawn at spawn locations named LobbySpawn. Then when a player touches a part they’re removed from the LobbyTable, added to the BattlegroundsTable, and then only spawn at spawn locations named BattlegroundsSpawn.

1 Like

maybe remove the other spawn locations on the client side?
i don’t know how to make a player spawn to a specific spawn location

1 Like

That’s inefficient, I’d have to clone and destroy a bunch of spawns depending on what table a player is in and a bunch of other stuff

1 Like

Have you tried using teams?
placeholderplaceholderplaceholder

2 Likes

When a player is added, add them to the lobby table. Check for death, and when they die, wait until they have respawned and then teleport them to a random spawn location.

Let’s assume you have all the spawns in a folder in workspace. When they player has respawned, loop through all spawn points for Spawns,ChosenSpawn in pairs(SpawnsFolder:GetChildren) then assign the player property SpawnLocation to the random spawn chosen. and you have to reload them

For the touching part, remove the player from the Lobbytable and add them to battleground table, then repeat

I hope this helps, and im terrible at explaining ik

2 Likes

Thing is I need players to be able to damage eachother. So let’s say we use teams. I don’t want players on LobbyTeam to be able to damage eachother. But I want players on BattlegroundsTeams to be able to damage eachother

1 Like

do you know how to code damaging teammates?

1 Like

Could you show this in a visual form? Like how would I structure this? I’ve already got the part down about adding them to the lobby table when they join

1 Like

I’m sorry, but I don’t have the time at the moment to explain this further as I am busy.

You’ll have to ask someone else to help you, but I wish you the best of luck with your project.

2 Likes

@Disreceded @Aurution I’ll explain what I’m trying to achieve better.

So we have 2 tables, one named LobbyTable, one named BattlegroundsTable. Then we have 2 folders with spawn locations inside of them. These folders are called Lobby Spawns & Battlegrounds Spawns, the spawn locations inside those folders are named after the folder they’re in (LobbySpawn & BattlegroundSpawn). When a player first joins they’re added to the LobbySpawn table, I want to set it up so if they’re in that table they’ll only spawn at spawn locations named LobbySpawn. Then the rest is easy, when they touch a specific part they’re removed from the lobbyspawn table and added to the battlegroundstable. Then if they’re in the BattlegroundsTable they’ll only spawn at spawn locations named BattlegroundSpawn.

I need help figuring out how to check if a player is in a table (for this example let’s use the LobbyTable). Then if they’re in that table they’ll only spawn at spawn locations with that name (Following the example - if a player is in LobbyTable then they’ll only spawn at spawn locations named LobbySpawn).

local lobbyTable = {}
local lobbySpawns = ---spawnLocationPath:GetChildren()
local touchPart = --touchPart go find it
game.Players.PlayerAdded:Connect(function(plr)
      table.insert(lobbyTable, plr)
      plr.CharacterAdded:Wait()
      local Character = plr.Character
      local hrp = Character:FindFirstChild("HumanoidRootPart")
      hrp.Position = lobbySpawns[math.random(1, #lobbySpawns].Position
end
touchPart.Touched:Connect(function(other)
       if game.Players.GetPlayerFromCharacter(other.Parent) then
             table.remove(lobbyTable, table.find(lobbyTable, game.Players.GetPlayerFromCharacter(other.Parent))

       end
end)

this is unfinished try this out to see if it works

Use teams

Blockquoteemphasized text

Alrighty, ill try it right after this - (chat gpt)

local player = game.Players
LobbyTable = {}

game.Players.PlayerAdded:Connect(function(player)
	table.insert(LobbyTable, player)
	print("Player added to lobby table")
end)

if table.find(LobbyTable, player) then
	print("Player is in lobby table")
	local spawnFolder = game.Workspace:FindFirstChild("Spawns")
	local spawnLocations = spawnFolder:GetChildren()
	local filteredLocations = {}

	for i, location in ipairs(spawnLocations) do
		if location.Name == "LobbySpawn" then
			table.insert(filteredLocations, location)
		end
	end

	local spawnLocation = filteredLocations[math.random(1, #filteredLocations)]
	player.Character:SetPrimaryPartCFrame(spawnLocation.CFrame)

end

Nope didnt work, idk why it wouldnt

player.Character:SetPrimaryPartCFrame(spawnLocation.CFrame)

just use humanoidrootpart and change the position

You can use teams, first assign a team like “Lobby” or “Battlegrounds”, then based on the team use math.random() to get a random one, or if you don’t want teams you can simply use the math.random() method and put them in a table manually

Also there’s no need to change the position, you can simply kill them