Is there a way to see if the Table is Empty and Has No Players in it? And Also to restart the While True Do Loop?
if #tabl == 0 then
--Its empty
end
Can you provide more information on your question.
If you want to restart a while true do loop…
while true do
while true do
if condition == true then --Restart this while true do loop.
break
end
end
end
i want to break the general loop heres an example of what im talking about.
while true do -- Base Loop.
--Audio Files and Other things
repeat wait() until #game.Players:GetPlayers() >= 2
--Heres the Table where the breaking loop would happen
Why do you have a while true do loop? You are only wanting to do those audio files and other things once and when 2 players join, you want to break the loop. So don’t do the loop in the first place.
function stuff() —Audio files and other stuff
end
Game.Players.PlayerAdded:Connect(function(player)
if #game.Players:GetChildren() >= 2 then
—Whatever code is under your repeat wait until.
end
end)
[Don’t expect another reply from me for atleast 9 hours… Tis time to sleep.]
To check a table’s length, do this:
t = {a,b,c}
print(#t) -- prints table length
To break the while loop if there are more than two players in the game do this:
while true do
if #game.Players:GetPlayers() < 2 -- less than two players
-- do stuff
else
-- do whatever you would do when there are more than two players
break -- breaks the loop
end
end
the while true that i use also disables and enables scripts and sets the games status
You might want to look into organizing your scripts so different parts of your game are handled separate from other parts. This is not like coding python or C++ where you have one game loop, so you have to adapt to this style of object-oriented programming and realize that not all of your scripts will run frame by frame on ROBLOX. Took me a while to get used to but it will make your life so much easier when you script this way.
local tab = {} -- your table
while true do
if #tab < the required amount then return end
wait()
end