Hey scriptinghelpers, I'm working on a minigame type of game. I'm having a problem when teleporting the players. Sometimes like if they reset, fall off the map, or whatever it is if they die when it tries to teleport them it breaks the game. I was wondering how I could fix this. Below you will find part of my code, I would provide the whole thing but, it's really long and you don't need it all so it will only be the teleporting part.
Edit: I changed the script to the solution.
This is a Script inside of ServerScriptStorage.
local function resetPlayers() game.Workspace.TP.NumberOne.Value = "" game.Workspace.TP.BoolValue.Value = false for _, player in pairs (game.Players:GetChildren()) do if player.Character:FindFirstChild("HumanoidRootPart") then player.Character.HumanoidRootPart.CFrame = CFrame.new(lobby) else end end end local function teleportPlayers() for _, player in pairs (game.Players:GetChildren()) do if player.Character:FindFirstChild("HumanoidRootPart") then player.Character.HumanoidRootPart.CFrame = CFrame.new(obby) else end end end
You can add a if statement to check for the humnaoidrootpart.
if player.Character:FindFirstChild("HumanoidRootPart") then --teleport code end
for _, player in pairs (game.Players:GetChildren()) do if player.Character:FindFirstChild("HumanoidRootPart") then player.Character.HumanoidRootPart.CFrame = CFrame.new(obby) end end