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

How do i make Players Teleport to different determined locations?

P1 = game.Workspace.P1
	P2 = game.Workspace.P2
	P3 = game.Workspace.P3
	P4 = game.Workspace.P4
	P5 = game.Workspace.P5
	P6 = game.Workspace.P6
	P7 = game.Workspace.P7
	P8 = game.Workspace.P8
	wait(2)
	players = game.Players:GetChildren()
	for i = 1,#players do
	if i == 1 then 
		players[1].CFrame = P1.CFrame
	end
	a = game.Workspace:WaitForChild(player.Name)
	a.Torso.CFrame = game.Workspace.P1.CFrame
	
	end

I know that this script is wrong but i dont know how i would go about this

2 answers

Based off of Huner's answer, but improved and fixed the code.

wait(2) -- Wait in seconds
x =  -- Gets players
for i,v in ipairs(game.Players:GetPlayers()) do
    if v.Character then
        v.Character.Torso.CFrame = game.Workspace.P1.CFrame
    end
end

Here, let me clean this up and explain it for you:

You don't need all those variables, you can just find the parts by the index number. Also, the player doesn't have a CFrame value, it's the character that does.

wait(2) -- Wait in seconds
x = game.Players:getChildren() -- Gets players
for i = 1, #x do -- Loops through players
	if x[i]:findFirstChild("Character") then
		x[i].Character.Torso.CFrame = game.Workspace:findFirstChild("P"..i) --Finds part based on index number
	end
end

3 comments

0

Character is a property, not a child, so findFirstChild will never return what you want. Fix this to change my downvote to an upvote.

0

how would this be fixed?

0

It would work as I use it for many other scripts. It's fine, he made a mistake.

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