Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

This script keeps returning errors in output? when v isn't a table its one?

Workspace.Limitations:5: attempt to call local 'AllPlayersInGame' (a table value) when I put v to not make it a table value

local Player = game:GetService("Players")

local AllPlayersInGame = Player:GetPlayers()

  

while wait(1) do

for i,v in pairs(AllPlayersInGame()) do

local thePlayer = tostring(v.Name)

print(thePlayer)

end

end

4 comments

0

I don't know if this will help because I never did anything like that. But see what happens when you remove the "()" from from "AllPlayersInGame".

0

Remove the parentheses in Line 9 on pairs(AllPlayersInGame())

0

Yes, you should remove the parenthesis. AllPlayersInGame is a table, not a function. GetPlayers() returns a table.

0

Also, "tostring(v.Name)" is unnecessary because Name itself is a string.

1 answer

AllPlayersInGame is a table

And you're trying to call it, and it has no __call metamethod, and will thus error. Simply removing the parenthesis () will fix it.

Player is a misleading identifier for your variable that contains the Players service. It is not referring to a specific player, but the players service. Also, your table will not update if a player joins or leaves.

Finally, do not use while wait(t) do ... end. This is not a good idiom to follow. It only works because of a hack; a trick.

Use

while (true) do
	--// ...
end

It's clearer.

local Players = game:GetService("Players");

while (true) do
	for _, client in ipairs(Players:GetPlayers()) do
		print(client); --// no need for tostring
	end
	wait(1);
end

This discussion is preserved as it was. New answers, comments, and votes are closed.