Hello! I have made a for loop that loops through the players and teleports them as well as a few other things. But it keeps repeating every 10 seconds or so, and I am very confused.
Code, in ServerScriptService
:
local players = game:GetService("Players")
local amount = #players:GetPlayers()
local status = game.ReplicatedStorage.StatusValue
plrready = 0
players.PlayerAdded:Connect(function(player)
amount = amount + 1
end)
players.PlayerRemoving:Connect(function()
amount = amount - 1
end)
while true do
wait()
print(amount)
if amount >= 2 then
game.ReplicatedStorage.StatusValue.Value = "players found, starting game momentarily"
wait(15)
for i, v in pairs(game.Players:GetChildren()) do
if v.InGame.Value == false then
game.ReplicatedStorage.GameStartEvent:FireClient(v)
v.PlayerGui.TextGui.Enabled = true
v.InGame.Value = true
v.Character:FindFirstChild("HumanoidRootPart").CFrame = game.Workspace.TeleportPart.CFrame
v.InGame.Value = true
end
end
status.Value = "investigate the area"
wait(100)
else
game.ReplicatedStorage.StatusValue.Value = "waiting for more players"
wait(.5)
game.ReplicatedStorage.StatusValue.Value = "waiting for more players."
wait(.5)
game.ReplicatedStorage.StatusValue.Value = "waiting for more players.."
wait(.5)
game.ReplicatedStorage.StatusValue.Value = "waiting for more players..."
wait(.5)
end
end
Does anyone know why this happens? Thank you and happy holidays!