Hi, i'm making a script that has to teleport all players to a location but it only teleports the first player joined.
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(67.75, 14.75, 0.75)
character:WaitForChild("Humanoid").Sit = false
local workspace = game:GetService("Workspace")
workspace.Game.House.NightInvisibleWalls.Bedroom.CanCollide = true
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Sleep well!"
wait(15)
local lighting = game:GetService("Lighting")
lighting.ClockTime = 24
lighting.FogEnd = 60
player.PlayerGui.TextGui.Frame.BackgroundTransparency = 0
character.HumanoidRootPart.Anchored = true
workspace.Game.Sounds.Music:Stop()
workspace.Game.Sounds.Night:Play()
player.PlayerGui.TextGui.Frame.BackgroundTransparency = 0
character.HumanoidRootPart.Anchored = true
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
wait(5)
player.PlayerGui.TextGui.Frame.TextLabel.Text = ""
local workspace = game:GetService("Workspace")
wait(15)
workspace.Game.House.NightSounds.Whispers.Sound:Play()
end
end
end
end
Full script:
db = true
while wait(1) do
if db == true then
if game:GetService("Workspace").Game.PlayerCount.Value >= 1 then db = false
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Welcome to Snowed in!"
end
end
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Giving players 1 minute to join."
end
end
wait(60)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Players are chosen, nobody can enter the round anymore."
end
end
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "The night will approach shortly."
end
end
wait(60)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Everyone goes to their beds, the night is here."
local lighting = game:GetService("Lighting")
lighting.ClockTime = 24
end
end
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
character:WaitForChild("Humanoid").Jump = true
character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(67.75, 14.75, 0.75)
local workspace = game:GetService("Workspace")
workspace.Game.House.NightInvisibleWalls.Bedroom.CanCollide = true
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Sleep well!"
wait(15)
local lighting = game:GetService("Lighting")
lighting.ClockTime = 24
lighting.FogEnd = 60
player.PlayerGui.TextGui.Frame.BackgroundTransparency = 0
character.HumanoidRootPart.Anchored = true
workspace.Game.Sounds.Music:Stop()
workspace.Game.Sounds.Night:Play()
player.PlayerGui.TextGui.Frame.BackgroundTransparency = 0
character.HumanoidRootPart.Anchored = true
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
wait(5)
player.PlayerGui.TextGui.Frame.TextLabel.Text = ""
local workspace = game:GetService("Workspace")
wait(15)
workspace.Game.House.NightSounds.Whispers.Sound:Play()
end
end
end
end
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "ZzZz, h-huh? w-what whas t-that sound?"
player.PlayerGui.TextGui.Frame.BackgroundTransparency = 1
character.HumanoidRootPart.Anchored = false
local serverstorage = game:GetService("ServerStorage")
local stairsmonster = serverstorage.StairsMonster:Clone()
stairsmonster.Parent = game:GetService("Workspace")
wait(10)
stairsmonster:Remove()
end
end
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Probably nothing, lets sleep further."
wait(5)
player.PlayerGui.TextGui.Frame.BackgroundTransparency = 0
character.HumanoidRootPart.Anchored = true
player.PlayerGui.TextGui.Frame.TextLabel.Text = ""
end
end
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "A new day has begun, everyone go to breakfast."
player.PlayerGui.TextGui.Frame.BackgroundTransparency = 1
character.HumanoidRootPart.Anchored = false
local workspace = game:GetService("Workspace")
workspace.Game.House.NightInvisibleWalls.Bedroom.CanCollide = false
workspace.Game.Sounds.Music:Play()
workspace.Game.Sounds.Night:Stop()
local lighting = game:GetService("Lighting")
lighting.ClockTime = 12
lighting.FogEnd = 100000
end
end
wait(15)
for i,player in pairs(game:GetService("Players"):GetChildren()) do
local character = player.Character
if character:WaitForChild("IsInRound").Value == true then
player.PlayerGui.TextGui.Frame.TextLabel.Text = "Eat well!"
character:WaitForChild("Humanoid").Jump = true
character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(1.75, 3, 0)
local workspace = game:GetService("Workspace")
workspace.Game.House.DayInvisibleWalls.MainRoom.CanCollide = true
local serverstorage = game:GetService("ServerStorage")
local food = serverstorage.Food:Clone()
food.Parent = game:GetService("Workspace")
wait(5)
player.PlayerGui.TextGui.Frame.TextLabel.Text = ""
wait(55)
food:Remove()
end
end
end
end
end

4 comments
That's because the script runs when the first player joins
It is a script in serverscriptservice with a debounce.
You are running a loop that iterates through the children of players to teleport players, however a :GetChildren() loop doesn't apply a code to all of them at the same time, it goes through each 1 by 1 and runs the code on that child. You are waiting 5 and then 55 seconds inside that loop, so it will be 60 seconds inbetween each player teleport
Is there another way to do it?