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

How would I find all players in game in one message?

Asked by
ACHRONlX 255 Moderation Voter
5 years ago

I have tried creating a table and adding player names into it when they join and removing it when they leave, however that hasn't worked. Can anyone tell me how I would make the webhook print every player in game's name?

01local players = {}
02 
03local url = ""
04local http = game:GetService('HttpService')
05 
06 
07game.Players.PlayerAdded:Connect(function(p)
08table.insert(players, p.Name)
09 
10end)
11 
12game.Players.PlayerRemoving:Connect(function(p)
13local finder = table.find(players, p.Name)
14if finder then
15table.remove(players.p.Name)
View all 26 lines...

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01local playersTable = {}
02local http = game:GetService("HttpService")
03local url = ""
04 
05game.Players.PlayerAdded:Connect(function(player)
06    for _,oldPlayer in pairs(game:GetService("Players"):GetPlayers()) do
07        if not table.find(playersTable, oldPlayer.Name) then
08            table.insert(playersTable, oldPlayer.Name)
09        end
10    end
11 
12    player.Chatted:Connect(function(msg)
13        if msg:sub(1,8) == ":players" then
14            local jsonTable = http:JSONEncode(playersTable)
15            local data = {
View all 27 lines...

The code looks messy, so it's hard to tell what the error is exactly.

But, my assumption is that you're trying to use a non-JSON table?

Not 100% sure, just a guess. But, this should work. Hope this helped!

Ad

Answer this question