How can I fix teleport script

So I have this problem when people with bad connection or something try to be teleport somewhere else which causes the whole game script to die is there a way I could skip the person aka not teleport them if their body part isn’t found in time?

for i,v in pairs(game.Players:GetChildren())do
			if v.TeamColor =="Bright red") and v.TeamColor =="Bright blue") then
  				local spawns = mapstorage["Map"..MapNum]:WaitForChild('Spawns'):GetChildren()
 				local spawne = math.random(1, #spawns)
 				local randomspawn = spawns[spawne]
				if v.Character == nil then
					v.Character:WaitForChild("UpperTorso").CFrame = +,2,0))
					v.Character:WaitForChild("UpperTorso").CFrame = +,2,0))

In your code it looks like you are still trying to teleport them even if their character isn’t found.

You should also use ipairs() and the game.Players:GetPlayers() function as it ensures you only get the player objects.

yes but how can I skip the player if the upper torso isn’t not found in ime

if (v.Character ~= nil) then
	local torso = v.Character:FindFirstChild("HumanoidRootPart")
	if (torso ~= nil) then
		torso.CFrame = +,2,0))

A part named ‘HumanoidRootPart’ should exist in both R15 and R6 characters, and also acts as the character model’s PrimaryPart.

1 Like