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

I want the game to get all children & book them in a var?

I want the game to get all the children players and book them in a variable then teleport them and this is the script:

local ppirates = game.Players:GetChildren()
    for x=1, #ppirates do
	if ppirates[x] ~= nil then 
		if ppirates[x] ~= nil then
			if ppirates[x].Character:findFirstChild("Torso") ~= nil then
				ppirates[x].Character.Torso.CFrame = CFrame.new(pos+Vector3.new(243,1.5,-225.4))

The problem is that it does not work. Why? How can I fix it?

2 answers

local players = game.Players:GetPlayers()
for i,v in pairs(players) do 
	if v.Character then 
		v.Character:MoveTo(Vector3.new(243,1.5,-225.4))
	end
end

2 comments

0

No explanations?

0

The only part he didn't do was MoveTo() and that's pretty self explanatory, once you look at the script.

On line 6 you are calling a variable pos, but from what I see, that variable is not declared, I presume that you are trying to add to the the player's position, which you don't need to do. You can just do this:

ppirates[x].Character:MoveTo(Vector3.new(243, 1.5, -225.4))

That'll teleport the player to those coordinates. About booking the players into a variable, you can declare a table and insert each player into that table, but you'll have to modify the table each time a player disconnects and each time a player joins the game, or the table will be out-of-date.

Or a simpler way:

players = game.Players:GetPlayers()
for _, v in pairs(players) do
	if(v.Character) then
		v.Character:MoveTo(Vector3.new(243, 1.5, -225.4))
	end
end

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