Spawning system issue

Hey everyone! So I am trying to make a 1v1 system, and I have the rest of the code working, the only thing I cannot figure out is how to make it so that only one player can spawn on the spawn pads I have (Not spawn locations).

My spawn function:

function SpawnPlayer(player,Location)
	local RandomSpawnIndexNumber = math.random(1, #Location)
	local Spawn = Location[RandomSpawnIndexNumber]

	if Spawn then
		table.remove(Location,RandomSpawnIndexNumber)


		local TeleportPlayer = script.TeleportPlayer:Clone()
		TeleportPlayer.Player.Value = player
		TeleportPlayer.TeleportLocation.Value = Spawn
		TeleportPlayer.Disabled = false
		TeleportPlayer.Parent = workspace
	end

	game:GetService("Debris"):AddItem(workspace.TeleportPlayer, 10)
end

My Teleport script:

local player=script.Player.Value

local Spawn=script.TeleportLocation.Value

local Character=workspace:WaitForChild(player.Name,4)

local Head=workspace:WaitForChild("Head",4)

Character.Head.CFrame=Spawn.CFrame*CFrame.new(0,5.5,0)

If anyone knows my issue, please tell me!

1 Like

Personally I’d have a table,

local spawns = {spawnPart1 = false, spawnPart2 = false}

then I’d run a for loop through to see which one isn’t taken and then spawn that person on it.

for i,v in pairs(spawns) do
	if not v then
		v = true
		-- teleport player to this part
	end
end

I’m pretty sure this is what you’re trying to achieve.

1 Like

Didn’t work. What do you mean in the table where you say “SpawnPart1”? Because I put the path and tried to teleport them and it returned an error saying that SpawnPart1 was a bool value.

local spawns = {
	[game.Workspace.Spawns.P1] = false,
	[game.Workspace.Spawns.P2] = false
}
local spawns = {
	[workspace.Spawns.P1] = {false},
	[workspace.Spawns.P2] = {false},
}

local function SpawnPlayer(player)
	for i,v in pairs(spawns) do
		if v[1] == false then
			v[1] = true
			player.Character:MoveTo(i.Position)
			break
		end
	end
end

Sorry I may have made a mistake. Give this a look I managed to test it and it worked fine

Thanks mate! Really helped out!

No problem good luck with your 1v1 system!

1 Like