Hey developers I have a problem how do I insert the current players in the game inside of a table? I tried using loops maybe I’m not using them correctly and also I read 2 previous topics and it didn’t help. Thanks
local TableOfPlayers = game:GetService'Players':GetPlayers()
It would also help if you posted your code so people could see where you went wrong
Tay-bels are an interesting thing to learn, depending on your scenario you could get all the current in-game players by using game.Players:GetPlayers()
through a for i, v in pairs
loop
local IngamePlayers = {}
function StartGame()
for _, Player in pairs(game.Players:GetPlayers()) do
table.insert(IngamePlayers, Player.Name)
end
end
That works but how do I make a custom table where I can add or remove values(players).
This is my current script
MiniGameModule.GetPlayers = function()
local PlayersInGame = {}
for i,v in pairs(game.Players:GetPlayers()) do
table.insert(PlayersInGame, i, tostring(v.Name))
end
return PlayersInGame
end
You could implement custom functions to determine when you want to add/remove the Players inside the table, maybe something like this inside a CharacterAdded
& Died
Event?
for Number, Player in pairs(game.Players:GetPlayers()) do
if CharacterWhoDied.Name == Player.Name and table.find(PlayersInGame, CharacterWhoDied.Name) then
table.remove(PlayersInGame, Number)
end
end
I already have it implemented to check if a player in the table has died and if they did remove them. But I need a custom table that holds the players in the round. Basically I want to store in the table all of the players.
where are them peransithies???
There’s no difference between writing it as 'Players'
or ('Players')
. That’s just my preference
Would it have a different result if you wrote it as "Players"
instead of 'Players'
?
tostring(v.Name)
is unneeded as the player’s name is already a string.
I don’t think it still wouldn’t make any difference
I believe you could do in either ways:
local Players = game:GetService("Players")
local Players = game:GetService('Players')
local Players = game:GetService"Players"
local Players = game:GetService'Players'
Didn’t know that you could do it without the parenthesis