Players spawn under map after teleport

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

  1. What do you want to achieve? Keep it simple and clear!
    I want to teleport players to a spawn thats not already been used by another player.

  2. What is the issue? Include screenshots / videos if possible!
    Sometimes (in both studio and real game) one player spawns below the map.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried many solutions (see my script below)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

	for i, plr in pairs(game.Players:GetPlayers()) do
		if plr:WaitForChild("Playing").Value == true then
			local SameMatch = Instance.new("BoolValue")
			SameMatch.Parent = plr
			SameMatch.Name = "SameMatch"
			plr:WaitForChild("Matches").Value = plr:WaitForChild("Matches").Value + 1
			plr.CameraMinZoomDistance = 0.5
			plr.CameraMaxZoomDistance = 0.5
			plr.CameraMode = Enum.CameraMode.LockFirstPerson
			plr.Character.Humanoid.MaxHealth = plr.Stats.Health.Value
			wait()
			plr.Character.Humanoid.Health = plr.Stats.Health.Value
			local Character = plr.Character

			if Character:FindFirstChild("HumanoidRootPart") then

				plr.Character.Humanoid.WalkSpeed = plr.Stats.WalkSpeed.Value
				plr.Character.Humanoid.JumpPower = plr.Stats.JumpPower.Value
				
				local Rand = Random.new()
				local Spawns = game.Workspace.Map.Spawns:GetChildren()
				local ChosenSpawn = Spawns[Rand:NextInteger(1, #Spawns)]
				
				if ChosenSpawn.Enabled == false then
					ChosenSpawn.Enabled = true
					print(ChosenSpawn.Position)
					print("Spawn found in first try")
					--wait()
					plr.Character:SetPrimaryPartCFrame(CFrame.new(ChosenSpawn.Position + Vector3.new(0, 10, 0)))
					--plr.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame + Vector3.new(0,10,0)
					--wait(1)
					--plr.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame + Vector3.new(0,10,0)
				elseif ChosenSpawn.Enabled == true then
					local Found = false

					repeat
						AlternativeSpawn = Spawns[Rand:NextInteger(1, #Spawns)]
						print("Searching for alternative spawn")
						if AlternativeSpawn.Enabled == false then
							AlternativeSpawn.Enabled = true
							print("Alternative spawn found")
							Found = true
							--wait()
							plr.Character:SetPrimaryPartCFrame(CFrame.new(AlternativeSpawn.Position + Vector3.new(0, 10, 0)))
							--plr.Character.HumanoidRootPart.CFrame = AlternativeSpawn.CFrame + Vector3.new(0,10,0)
							--wait(1)
							--plr.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame + Vector3.new(0,10,0)
						end
					until Found == true
				end		
			elseif not Character:FindFirstChild("HumanoidRootPart") then
				
				repeat wait()
					
				until Character:FindFirstChild("HumanoidRootPart")
				
				plr.Character.Humanoid.WalkSpeed = plr.Stats.WalkSpeed.Value
				plr.Character.Humanoid.JumpPower = plr.Stats.JumpPower.Value

				local Rand = Random.new()
				local Spawns = game.Workspace.Map.Spawns:GetChildren()
				local ChosenSpawn = Spawns[Rand:NextInteger(1, #Spawns)]

				if ChosenSpawn.Enabled == false then
					print("Found spawn in first try")
					print(ChosenSpawn.Position)
					ChosenSpawn.Enabled = true
					--wait()
					plr.Character:SetPrimaryPartCFrame(CFrame.new(ChosenSpawn.Position + Vector3.new(0, 10, 0)))
					--plr.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame + Vector3.new(0,10,0)
					--wait(1)
					--plr.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame + Vector3.new(0,10,0)
				elseif ChosenSpawn.Enabled == true then
					local Found = false

					repeat
						AlternativeSpawn = Spawns[Rand:NextInteger(1, #Spawns)]
						print("Searching for alternative spawn")
						if AlternativeSpawn.Enabled == false then
							AlternativeSpawn.Enabled = true
							print("Alternative Spawn Found")
							Found = true
							--wait()
							plr.Character:SetPrimaryPartCFrame(CFrame.new(AlternativeSpawn.Position + Vector3.new(0, 10, 0)))
							--plr.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame + Vector3.new(0,10,0)
							--wait(1)
							--plr.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame + Vector3.new(0,10,0)
						end
					until Found == true
				end		
			end
		end
		wait()
	end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

As far as I can tell, there isn’t anything in that script that would make your character spawn in the ground. It must be some other script that is doing it.

Code was messy, so I rewrote it:

local Players = game:GetService("Players")

for _, player in next, Players:GetPlayers() do
	if player:WaitForChild("Playing").Value then
		local SameMatch = Instance.new("BoolValue")
		SameMatch.Name = "SameMatch"
		SameMatch.Parent = player
		
		player:WaitForChild("Matches").Value += 1
		player.CameraMinZoomDistance = 0.5
		player.CameraMaxZoomDistance = 0.5
		player.CameraMode = Enum.CameraMode.LockFirstPerson
		task.wait()
		
		local character = player.Character
		local humanoid = character:WaitForChild("Humanoid")
		local rootPart = humanoid.RootPart
		
		humanoid.MaxHealth = player.Stats.Health.Value
		humanoid.Health = humanoid.MaxHealth
		humanoid.WalkSpeed = player.Stats.WalkSpeed.Value
		humanoid.JumpPower = player.Stats.JumpPower.Value
		
		local Rand = Random.new()
		local Spawns = workspace.Map.Spawns:GetChildren()
		local ChosenSpawn = Spawns[Rand:NextInteger(1, #Spawns)]
		
		while not ChosenSpawn.Enabled and task.wait() do
			ChosenSpawn = Spawns[Rand:NextInteger(1, #Spawns)]
			print("Searching for alternative spawn")
			
			if not ChosenSpawn.Enabled then
				print("Alternative spawn found")
				ChosenSpawn.Enabled = true
			end
		end
		
		rootPart.CFrame = CFrame.new(ChosenSpawn.Position + Vector3.new(0, 10, 0))
	end
end
1 Like

Oh, thanks anyways. Also thanks for your version of the script, thats definitely helpfull :smiley: