Tab your code properly. The Glossary has this covered.
See how there's a big space at the beginning of lines 5 through 20 in your code?
That shows that all of that code is grouped inside the while on line 4.
You should do that for everything that groups code together -- then ... else ... end, do ... end, etc.
This makes it possible for you to understand what code happens when. Without it, you have to spend way too much time figuring out which ends go where and which conditions matter.
local players = game.Players:GetChildren()
local h = script.Value
local playertable = {}
while true do
wait(3)
if game.Players.NumPlayers == 1 then
print("Gettingpairs")
for i,v in pairs(game.Players:GetPlayers()) do
if v and v.Character then
table.insert(playertable,v)
end
print(#playertable)
if #playertable == 1 then
print("Break out of the whiletruedo")
break
else
print("keep going")
end
end
end
end
print("yo,game over")
It is clear that this is not correct.
- lines 12 .. 18 have nothing to do with
i or v, but they're inside the for loop. They probably belong after.
- you never use
players defined at the top (it's useless)
You only ever add things to playertable . You never remove. That means it's just going to grow. You probably want to just filter down the currently running players; it should be initialized to {} inside the loop.
A name like "playertable" isn't that informative. Normally you'd just use a plural like players instead of including the fluff word "table"
Use meaningful names. I don't know what a v is. You don't use i and it also doesn't mean anything.
while true do
wait(3)
if game.Players.NumPlayers == 1 then
print("Gettingpairs")
local players = {}
for _, player in pairs(game.Players:GetPlayers()) do
if player and player.Character then
table.insert(players, player)
end
end
print(#players)
if #players == 1 then
print("Break out of the whiletruedo")
break
else
print("keep going")
end
end
end
print("yo,game over")
I'm not sure what the point of the game.Players.NumPlayer == 1 check is. It seems superfluous.
Because your code originally didn't make sense, and because it has no comments or explanation from you, I'm not sure what your intent is.
4 comments
You never clear the playertable
What
Tab your code properly.
I Thought this was scripting helpers, where you can help people with their code. If you could please help me learn tabbing and show me the problem that would be great!