Loading/Teleporting Bug

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    Some type of way to make it so people don’t load at exactly the same time and then spawn on the same pad because of it.

  2. What is the issue?
    When people spawn in, if they spawn in simultaneously then they get teleported onto the same pad which shouldn’t happen.

  3. What solutions have you tried so far?
    I tried adding a queue time which didn’t work, adding waits or randomized waits didn’t work either.

local TeleportWithinPlace = require(game.ReplicatedStorage:WaitForChild("TeleportWithinPlace"))

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character)
		wait()
		if Player.Team == game.Teams.Lobby or Player.Team == game.Teams.Staff then
			return
		else
			local pillars = game.Workspace.Pillars:GetChildren()
			for i,v in pairs(pillars) do
				if v.Name == "Pillar" then
					local spawnL = v:FindFirstChild("SpawnPart")
					print(spawnL)
					local humanoid = character:WaitForChild("Humanoid")
					humanoid.WalkSpeed = 0
					local TELEPORT_DESTINATION = spawnL.Position
					local TELEPORT_FACE_ANGLE = 0
					local FREEZE_CHARACTER = true
					if humanoid and not humanoid:GetAttribute("Teleporting") then
						humanoid:SetAttribute("Teleporting", true)
						local params = {
							destination = TELEPORT_DESTINATION,
							faceAngle = TELEPORT_FACE_ANGLE,
							freeze = FREEZE_CHARACTER
						}
						print(TELEPORT_DESTINATION)
						TeleportWithinPlace.Teleport(humanoid, params)
						wait(1)
						humanoid:SetAttribute("Teleporting", nil)
						humanoid.WalkSpeed = 0
					end
					v.Name = Player.Name
					return
				end
			end
		end
	end)
end)

you can use :GetTouchingParts to check if a player is on the pad if they are then don’t teleport yet wait for them to get out of the pad then teleport the next player.

You can also limit how many players is able to stand on the pad or check if the previous player has already been teleported this will prevent people from abusing the system.

They can’t get out of the pad, hence setting their walkspeed to 0. They’re meant to stay on the pad and are unable to get off of it until they’re dead. I don’t really think :GetTouchingParts would work the best for the script considering that CanCollide has been turned off for the players.

Can’t you just add multiple pads and make it so it loops through each one and check if someone is on it or not

This problem should probably be handled in the place receiving the players. The amount of time it takes players to teleport varies greatly, so changing when you teleport the players won’t solve the problem.

In your other place, I’d just create a list of all the possible spawn positions

-- Ex:
{
    {spawn1, true},
    {spawn2, false},
    {spawn3, false},
    -- etc.
}
-- (You should probably put all the spawns in a folder, then
-- when the game starts create a list like the one above from
-- `GetChildren()`)

Then when a player is added loop through the spawn points and find an open one.

That’s what it currently does, but the thing is if they simultaneously load in then the script runs at the same time. Meaning that they both think that the same pillar is free, causing them both to spawn on it

Oh okay I should’ve probably read the script first lol

I’ve decided to instead of rely on players not loading at the same time to change the way it functions and what causes the players to spawn on the pads, meaning there’s no longer a need to fix this script as it wasn’t reliable to hope or change how players load into the game

@PersonifiedPizza
This is the only place, the teleportation is handled in game and doesn’t send players from one place to another

Oh I see, I thought you meant teleporting like TeleportationService:Teleport(). I’d still recommend a queue, though I’m sure your solution will work too.