Teleport to top of map player before dying

game.Players.PlayerAdded:Connect(function(player)
	while true do
		if player.Character:WaitForChild("HumanoidRootPart").CFrame.Y <= game.Workspace.FallenPartsDestroyHeight.Value + 50 then
			player.Character.HumanoidRootPart.Cframe = CFrame.new(-98.57, 125.885, 17.1)
		end
	end
	player.Character:MoveTo()
end)

Why isn’t this working? no errors but player is dying in void

I took this script into studio and found multiple errors that I noted bellow:

game.Players.PlayerAdded:Connect(function(player)
	while true do  -- will exhaust the server and not run
		if player.Character:WaitForChild("HumanoidRootPart").CFrame.Y <= game.Workspace.FallenPartsDestroyHeight.Value + 50 then  -- Value is not a child of FallenPartsDestroyHeight, also the server will have trouble finding player.Character
			player.Character.HumanoidRootPart.Cframe = CFrame.new(-98.57, 125.885, 17.1) -- Capitalize "CFrame"
		end
	end
	player.Character:MoveTo() -- You need a value here
end)

Here’s the modified code that will not have any errors, you can modify it to your liking:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		while wait(.1) do
			if char:WaitForChild("HumanoidRootPart").CFrame.Y <= game.Workspace.FallenPartsDestroyHeight + 50 then
				char.HumanoidRootPart.CFrame = CFrame.new(-98.57, 125.885, 17.1)
			end
		end
               -- I got rid of the :MoveTo() function completely since it didn't do anything
	end)
end)

Hope this helps!

local run = game:GetService("RunService")
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hrp = character:WaitForChild("HumanoidRootPart")
		while true do
			run.Stepped:Wait()
			if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
				character:PivotTo(CFrame.new(100, 125, 20)) --Use cleaner values here.
			end
		end
	end)
end)

Added some comments which should help explain what you did wrong.

Thank you guys for your responses, but on both of these i still die to void.

What value is your FPDH property set to? The default is -500.

-500, if i add a print statement it still doesnt run

local run = game:GetService("RunService")
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hrp = character:WaitForChild("HumanoidRootPart")
		print(game.Workspace.FallenPartsDestroyHeight)
		while true do
			print(player.Character.CFrame.Y)
			run.Stepped:Wait()
			if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
				character:PivotTo(CFrame.new(100, 125, 20)) --Use cleaner values here.
			end
		end
	end)
end)

no printsx are done here above

I figued it out, I need to say hrp.Cframe.Y
also is there a way to keep character from changing rotation? because it goes to default rotation when it spawns back in.

Has to be in a server script by the way.

local run = game:GetService("RunService")
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hrp = character:WaitForChild("HumanoidRootPart")
		print(game.Workspace.FallenPartsDestroyHeight)
		while true do
			run.Stepped:Wait()
			if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
				character:PivotTo(CFrame.new(0, 50, 0)) --Use cleaner values here.
			end
		end
	end)
end)

This is working for me when I test.

local run = game:GetService("RunService")
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hrp = character:WaitForChild("HumanoidRootPart")
		print(game.Workspace.FallenPartsDestroyHeight)
		while true do
			run.Stepped:Wait()
			if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
				hrp.Position = Vector3.new(0, 50, 0)
			end
		end
	end)
end)

If you want to maintain orientation only alter/modify the position. Change the position I used to any you desire.

when i use the code you gave me it desnt print anything and i also die to void

nevermind, there was an issue above it when i pasted it into a used server script, i made a new one and it worked.

it doesnt look smooth when i teleport to top of map, is there a way to make it so that the character doesnt slow down when they are teleported?

Nevermind figured it out, thanks for the help