I'm trying to make an array loop telling separating Players alive from Dead, only it doesn't seem to work as it only says I've been inserting one Player repeatedly, I ran this in a 3 Player test Server, this is the whole thing


spawn(function()
	while wait() do
		AllPlayers = {}
		for _,Player in pairs(game:GetService("Players"):GetPlayers()) do
			if Player and Player.Character then
				if Player.Character.Humanoid then
					table.insert(AllPlayers, Player)
				end
			end
		end
	end
end)

RegisteredtoLoop = {} --// there is code before this Loop runs, making sure it only sets them before the loop begins, although the code isn't necessary.
for _,Player in pairs(AllPlayers) do
	if Player and Player.Character then
		if Player.Character.Humanoid.Health > 0 then
			table.insert(RegisteredtoLoop, Player)
		end;
	end
end;

local CurrentPlayers = {}; local PlayersDead = {};

while running and runtime ~= 1 do
	for _,Player in pairs(RegisteredtoLoop) do -- Registered gets all the Players from the main loop 'AllPlayers' and puts them in an array for Players who were still alive before the loop started.
	if Player and Player.Character then
		if Player.Character.Humanoid.Health > 0 then
			table.insert(CurrentPlayers, Player)
				print(Player.Name.." was listed as Current."); print(table.concat(CurrentPlayers, " "))
			elseif Player.Character.Humanoid.Health < 1 then
				table.insert(PlayersDead, Player); table.remove(CurrentPlayers, Player)
				print(Player.Name.." was unlisted as Current; PlayerDead");  print(table.concat(CurrentPlayers, " "))
			end
		end
	end;
end;

I can't even print any of them, nothing but userdata errors, what am I doing wrong?

9 comments

0

while wait() do is deprecated

0

@MCAndRobloxUnited That is incorrect - some people argue that it should not be used, but Roblox isn't removing support for it

0

while wait(...) do is slower than while true do wait() end. It would be fair to call it deprecated. Cool document by cntkillme. https://docs.google.com/document/d/1ieZ8OzXPiXe3R7rs_xWmYZOnhQevlagN0ZWwoj_zKP4/

0

None of the arguments presented in that document are sound. View it as a formatting style choice and neither of the negatives hold, and the benefits don't matter because formatting style is largely preference. Very similar arguments could be applied to using "if" statements without curlybois in C-like languages - a practice often viewed as acceptable.

0

Why is the first bit run asynchronously? It doesn't seem to require it, and I'd probably be the most suspicious of parallelism if there's a weird bug in your code.

0

Also you never actually use the table RegisteredToRound

0

Opps, that's my bad, I wrote the Registered variable wrong, i did use it in the loop, it's supposed to be spelled 'RegisteredtoLoop', I fixed it in the question.

0

'AllPlayers' is supposed to run asynchronously, it's separated from the thread so it can be constantly updated as it's main function is to track every new user entering E leaving.

0

Should I try to configure it to run without the parallelism method? Or am I correct to do this, as I tend to be using separating threads as a common method for Gamescritps, mainly Core types.