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

Function that teleports all players to a specific area?

How do I make a function to teleport every player to a certain area? The function should be called: TeleportAll() Help...

1 comment

0

Is this a request?

2 answers

✓ Accepted answer

An easy way would be like this:

local position = CFrame.new() -- enter your position between the parenthesis
function TeleportAll()
	for i, v in pairs(game.Players:GetPlayers()) do
		if v.Character then
			plr.Character.HumanoidRootPart.CFrame = position
		end
	end
end)

8 comments

0

Thx!

0

You should be using GetPlayers and not GetChildren, and you should declare the variable inside the function, and use CFrame, not position. You also shouldn't give answers to people who don't even try.

0

...

1

use :GetPlayers() not :GetChildren() and  you dont check is character is not nil.

0

:(

0

Fixed!

0

The players array won't update on its own. You should move it inside the function so you have an up to date array.

0

True... Not really any need for a variable at all.

its simple, you can use :GetPlayers() and for loop.

Examples:

-- 1 > Print player names

for i,v in pairs(game.Players:GetPlayers()) do -- Get all players with for loop
	print(v.Name) -- print player names!
end

-- 2 > Get character
for i,v in pairs(game.Players:GetPlayers()) do -- Get all players with for loop
	if v.Character then -- If find character then...
		print("Found char of player: " .. v.Name)
	else
		print("I cant get char of player: " .. v.Name)
	end
end

-- 3 > Change value
for i,v in pairs(game.Players:GetPlayers()) do -- Get all players with for loop
	if v:FindFirstChild("VALUE") then
		v["VALUE"].Value = "Your Value"
	end
end

Here is the fixed script:

local position = Vector3.new(-28.84, 0.5, 0.12) -- or you can use CFrame.new(...,...,...,...)/ Put position here with cframe,vector3...! (I've put this in to make it easier for you to use the script.)

for i,v in pairs(game.Players:GetPlayers()) do -- get all players with for loop
	if v.Character then -- if character is not nil then
		if v.Character:FindFirstChild("HumanoidRootPart") then -- If find HumanoidRootPart
			v.Character["HumanoidRootPart"].CFrame = CFrame.new(position) -- Teleport player to position
			--[[if you dont like this, you can use :MoveTo
				v.Character:MoveTo(position)
			]]
		end
	end
end

Wiki pages:

Players:GetPlayers()

CFrame

Model:MoveTo()

For loop

Vector3

Hope it helped :D


Solved your problems? put in title [SOLVED] or accept a answer.

2 comments

0

local position = -28.84, 0.5, 0.12 position will be assigned to -28.84 and 0.5 and 0.12 are discarded.

0

Changed now

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