Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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
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". Alphexus 498 — 5y
0
Remove the parentheses in Line 9 on pairs(AllPlayersInGame()) Mirzadaswag 110 — 5y
0
Yes, you should remove the parenthesis. AllPlayersInGame is a table, not a function. GetPlayers() returns a table. DeceptiveCaster 3761 — 5y
0
Also, "tostring(v.Name)" is unnecessary because Name itself is a string. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

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

It's clearer.

```lua 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 ```

Ad

Answer this question