Player Teleport Help

I want the players in a folder in workspace to be teleported to a part’s position.
Teleport Code (server script)

for _,v in pairs(workspace.VersusQueue:GetChildren()) do	
v:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(workspace.VersusTP.Position)
end

Move to folder (local script)

game.ReplicatedStorage.JoinVersusQueue.OnClientEvent:Connect(function()
game.Players.LocalPlayer.Character.Parent = workspace.VersusQueue
end)
2 Likes

If you are moving the player character with a LocalScript it will actually never move to the Server, so this means that your “Script” will never find the players inside the folder. (Causing to dont teleport the players)

You could try to move The Player Character by a RemoteEvent.

I tired moving the player with a server script and it worked (in studio :sob:) but not when I played the game

When you move the characters to the folder in the local script, this change is not being replicated to the server, so when you try to iterate through the children of the folder in the server, it is empty. You will have to change the parent of the characters in a server script instead of a local script.

I changed it to a touch function in a server script and that works when I test in studio but not in the game.

Hi! I will paste the code to teleport all players here:

local target = CFrame.new(0,0,0)
for i, player in ipairs(game.Players:GetChildren()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
end
end

Replace numbers in target value with your brick position. Also you have to remeber that this code only works when it’s in the Script.
I didn’t understand everything that you want to achieve. Reply when you’ll need more support and describe your problem more. If you don’t, mark this reply as a solution to let me know that everything is fine.

That Script doesnt seem to work

for _,v in pairs(workspace.VersusQueue:GetChildren()) do	
    local hrp = v:FindFirstChild("HumanoidRootPart")
    if not hrp then return end
    hrp.Crame = CFrame.new(workspace.VersusTP.Position)
end

^ Amendment to your server script.

Do not reparent the character on the client side since clients don’t have control over that. Handle that on the server:

local Remote = game.ReplicatedStorage.JoinQueue

Remote.OnServerEvent:Connect(function(Player)
     if Player.Character then
         Player.Character.Parent = workspace.VersusQueue
     end
end)

The teleport doesn’t seem to work

My code assumes that the client fires a remote event called JoinQueue under ReplicatedStorage. Both pieces of code should go under a server script. Additionally, that for loop only runs once so it is up to you to make it run that loop when it is needed.

But it does. Try this:

  1. Create a Script in ServerScriptService.
  2. Open it up and write this:
while true do
wait(10)
local target = CFrame.new(0,0,0)
for i, player in ipairs(game.Players:GetChildren()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
end
end
  1. Click Play to test your game. I recommend doing this on empty Baseplate.

What does this Script do?
Every 10 seconds it teleports all players to locaction. In my case it’s (0,0,0).

Was this helpful?