I’m trying to call a function when there are more 2 or more players in the server. For some reason, the output is “Not enough players! (0/2)”. This is my code.
function RoundTimer()
while wait() do
for i = IntermissionLength,0,-1 do
InRound.Value = false
Status.Value = "Intermission ("..i.." seconds left)"
end
for i = RoundLength,1,-1 do
InRound.Value = true
Status.Value = "In game! ("..i.." seconds left)"
end
end
end
if #Players:GetPlayers() >= 1 or Players:FindFirstChild("zCrxtix") then
spawn(RoundTimer)
else
Status.Value = "Not enough players! ("..tostring(#Players:GetPlayers()).."/2)"
end
local Players = game.Players
function RoundTimer()
while wait() do
for i = IntermissionLength,0,-1 do
InRound.Value = false
Status.Value = "Intermission ("..i.." seconds left)"
end
for i = RoundLength,1,-1 do
InRound.Value = true
Status.Value = "In game! ("..i.." seconds left)"
end
end
end
if #Players:GetPlayers() >= 1 or Players:FindFirstChild("zCrxtix") then
spawn(RoundTimer)
else
Status.Value = "Not enough players! ("..tostring(#Players:GetPlayers()).."/2)"
end
This is because you are only calling this once. Have it in a while loop and check if every second:
while wait(1) do
if #Players:GetPlayers() >= 1 or Players:FindFirstChild("zCrxtix") then
spawn(RoundTimer)
else
Status.Value = "Not enough players! ("..tostring(#Players:GetPlayers()).."/2)"
end
end
local Players = game.Players
local Status = game.ReplicatedStorage.Status
local InRound = game.ReplicatedStorage.InRound
local RoundLength = 40
local IntermissionLength = 5
local TPs = game.Workspace.Teleports:GetChildren()
local ChosenTeleporter = math.random(1, #TPs)
local Player = Players:GetPlayers()
InRound.Changed:Connect(function()
if InRound.Value == true then
for _, player in pairs(Players:GetPlayers()) do
player.Character.HumanoidRootPart.Position = game.Workspace.Teleports[tostring(ChosenTeleporter)].Position + Vector3.new(0,3,0)
end
local Sword = game.ServerStorage.ClassicSword
for _, player in pairs(Players:GetPlayers()) do
wait(2)
Sword:Clone().Parent = player.Backpack
end
else
for _, player in pairs(game.Players:GetChildren()) do
player:LoadCharacter()
end
end
end)
function RoundTimer()
while wait() do
for i = IntermissionLength,0,-1 do
InRound.Value = false
Status.Value = "Intermission ("..i.." seconds left)"
end
for i = RoundLength,1,-1 do
InRound.Value = true
Status.Value = "In game! ("..i.." seconds left)"
end
end
end
while wait(1) do
if #Players:GetPlayers() >= 1 or Players:FindFirstChild("zCrxtix") then
spawn(RoundTimer)
else
Status.Value = "Not enough players! ("..tostring(#Players:GetPlayers()).."/2)"
end
end