Players die on teleportation in-game

Hello everyone, I have been working on a fun game which uses player teleportation to a map in-game. Unfortunately recently I have noticed that sometimes during testing, right after the player’s HumanoidRootPart CFrame has been moved to a spawnpoint in a map, the player dies. Sometimes it is a few seconds after teleportation. This has happened before, and at first I thought that it was because of a malicious script, since I do use free models sometimes, but I removed them and the problem still occurs. The only solution I found was to move over all of the stuff in my game to a new place. Please help! Thanks.

Here is my teleportation code:

for _, player in pairs(contestants) do
	if player and player.Character and #spawns > 0 then
		local torso = player.Character:FindFirstChild("HumanoidRootPart")
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local spawnindex = math.random(1, #spawns)
		local spawnx = spawns[spawnindex]
		if spawnx and torso and humanoid then
			humanoid.Health = 100
			humanoid.WalkSpeed = 16
			table.remove(spawns, spawnindex)
			if torso and player and humanoid then
				torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0, 3, 0))
			end

			local matchtag = Instance.new("StringValue")
			matchtag.Name = "MatchTag"
			matchtag.Parent = player.Character

			local backpack = player:FindFirstChild("Backpack")
			if backpack then
				if player == bloxxer then
					event:FireClient(player, "Class", "Bloxxer")

					local equippedpower = player:WaitForChild("EquippedPower")

					if equippedpower then
						if equippedpower.Value == "Ghost" then
							event:FireClient(player, "Ghost")
						elseif equippedpower.Value == "Sprint" then
							event:FireClient(player, "Sprint")
						elseif equippedpower.Value == "FakeGun" then
							local fakegun = serverstorage:WaitForChild("Fake Gun")
							fakegun:Clone().Parent = backpack
						elseif equippedpower.Value == "Shield" then
							event:FireClient(player, "Shield")
						end
					end

					local equippedknife = player:WaitForChild("EquippedKnife")

					local weapontogive = serverstorage:FindFirstChild(equippedknife.Value)

					if weapontogive then
						weapontogive:Clone().Parent = backpack
					end

				elseif player == sheriff then
					local equippedgun = player:WaitForChild("EquippedGun")

					local weapontogive = serverstorage:FindFirstChild(equippedgun.Value)

					if weapontogive then
						cloned = weapontogive:Clone()
						cloned.Parent = backpack
					else
						warn("No weapon to give!")
						cloned = serverstorage:FindFirstChild("Revolver"):Clone()
						cloned.Parent = backpack
					end

					local equippedpower = player:WaitForChild("EquippedPower")

					if equippedpower.Value == "FasterReload" then
						local val = cloned:WaitForChild("FasterReloadCheck")
						val.Value = 1
					end
					event:FireClient(player, "Class", "Sheriff")
				else
					event:FireClient(player, "Class", "Bystander")
					local equippedpower = player:WaitForChild("EquippedPower")

					if equippedpower.Value == "FakeGun" then
						local fakegun = serverstorage:WaitForChild("Fake Gun")
						fakegun:Clone().Parent = backpack
					end
				end
			end
		end
	end
end
1 Like

What is spawn.Position defined as exactly…?

1 Like

Oops I meant spawnx.Position and it is the position of one of my spawn parts (not a Spawnlocation) inside the chosen map

1 Like

Could it be possible that 1 of the spawnx positions are set in a different area? You could try printing out the Position of what it outputs back

1 Like

Well maybe, but the teleportation actually works, I mean what happens is that I get teleported and then like 1 second later, I’m dead and the round’s over

1 Like

I’ve had experience with this before. It’s because when your moving the character really quick, the head gets dislocated and thus, killing the character. Maybe use position?

2 Likes

Yes, that explains it! Thank you! I will try position. Does setting the position work?

1 Like

Yes it does as I assume. It sets the position straight forward while LookVector CFrame will move the character at incredible speeds and it’ll dislocate the head. I’m really glad to help a developer out!

2 Likes

It worked! I tried it right now and everything is working properly! Thanks so much! :heart:

1 Like