How do I make a function to teleport every player to a certain area? The function should be called: TeleportAll() Help...
Function that teleports all players to a specific area?
2 answers
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
Thx!
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.
...
use :GetPlayers() not :GetChildren() and you dont check is character is not nil.
:(
Fixed!
The players array won't update on its own. You should move it inside the function so you have an up to date array.
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:
Hope it helped :D
Solved your problems? put in title [SOLVED] or accept a answer.
2 comments
local position = -28.84, 0.5, 0.12 position will be assigned to -28.84 and 0.5 and 0.12 are discarded.
Changed now
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Is this a request?