Script not teleporting everyone

Hello : D

I have a script that should teleport all players to another section of the map after 100 seconds has passed however it only teleports one player?


wait(100)
for _,v in pairs(game:GetService(“Players”):GetPlayers()) do
if v.Character then
if v.Character:FindFirstChild(“HumanoidRootPart”) then
v.Character:FindFirstChild(“HumanoidRootPart”).CFrame = CFrame.new(76.25, -87.868, 91.151)
break
end
end – missing this end in the original fix
end

Can anyone help me with this?

1 Like

You can get all children from parent by doing # for example #GetChildren

1 Like

Simple because u broke the loop?

An for loop will end itself after looping through every character so there isn’t a need to do so

3 Likes

As said in @hestolemyrice’s post, using "break" inside of a loop will stop looping through what you specified after one time. You can view more about loops here: Introduction to Scripting | Documentation - Roblox Creator Hub

local players = game:GetService("Players")

for _, v in pairs(players:GetPlayers()) do
    if v.Character then 
       if v.Character:FindFirstChild("HumanoidRootPart") then
          local humanoidRootPart = v.Character:FindFirstChild("HumanoidRootPart") 
          humanoidRootPart.CFrame = CFrame.new(76.25, -87.868, 91.151)
      end
   end
end
2 Likes

Thank you for your help :slight_smile:

2 Likes