Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make people teleport?

local target1 = CFrame.new(0 - 178, 79, 0)
local target2 = CFrame.new(0 - 178, 205, 0)

if #(game.Players:GetChildren()) > 1 then
	for i, player in pairs(game.Players:GetChildren()) do
		
		
	end
end

if #(game.Players:GetChildren()) < 1 then
	for i, player in pairs(game.Players:GetChildren()) do
		
		
	end
end

There is no errors. It's just I don't know how to get people to teleport. When there are two people or more I want them to teleport to target1. When there are less then two people I want them to teleport to target2.

1 answer

✓ Accepted answer

Simple! Because all body parts are connected to the player , you can teleport the Torso to the CFrame position you want. So we'd first access the torso from that player. To do this, we'd find the Character member of th e of the player, then find the torso member of the character, like this: player.Character.Torso . Finally we'd set the CFrame property of the torso to whatever position you want. NOTE there are a couple of things that I might add, so bear with me if you don't understand. Here's the final script:


local target1 = CFrame.new(0 - 178, 79, 0)
local target2 = CFrame.new(0 - 178, 205, 0)

if #(game.Players:GetChildren()) > 1 then
    for i, player in pairs(game.Players:GetChildren()) do
	repeat wait() until player.Character ~= nil
	if player.Character.Humanoid.Health ~= 0 then
		player.Character.Torso.CFrame = target1
	end
    end
end

if #(game.Players:GetChildren()) < 1 then
    for i, player in pairs(game.Players:GetChildren()) do
		repeat wait() until player.Character ~= nil
		if player.Character.Humanoid.Health ~= 0 then
		player.Character.Torso.CFrame = target2
	end
    end
end

There are a couple small things I need to explain. In both pairs, I've added repeat loops. These are to make sure that the players Character is loaded before we set the torso's position. The next code that I added made sure that if the player that were indexing is dead or it's character/torso isn't loaded. This is to make sure that the next line of code doesn't error, because the player must have it's character loaded and it's health set to >0 to be teleported.

Hopefully this answer helped with your script. Of coarse there are a few other things that might need to be added to finish the concept off. If you have any questions, please post a comment below. Otherwise, I have some links for you below. YOUR WELCOME!!!

LINKS:

Roblox Wiki: http://wiki.roblox.com/index.php/Scripting

Tables: http://wiki.roblox.com/index.php?title=Table

The player: http://wiki.roblox.com/index.php?title=API:Class/Player

The Character: http://wiki.roblox.com/index.php?title=API:Class/Player/Character

This discussion is preserved as it was. New answers, comments, and votes are closed.