So I’m trying to make a system on how you can put a player name in a table and that player is then excluded to later functions that affect all the player but how would i actually exclude that player
target ~= game.Players:FindFirstChild(table.find(_G.excludedplayers)) then
To be honest, I never used global variables so I don’t really know how it works, but usually to check a value in a table I use table[name], however I am not sure if that would work in this case. What exactly is stored in the table?
local PlayerService = game:GetService("Players")
local exludedPlayers = {PlayerService.LocalPlayer}
local function someFunction()
for i, player in pairs(PlayerService:GetPlayers()) do
if table.find(exludedPlayers, player) then continue end
print(player.Name)
--Do your function here
end
end
A more general version:
local PlayerService = game:GetService("Players")
local function getIncludedPlayers(excluded)
local array = PlayerService:GetPlayers()
excluded = if excluded then excluded else {}
for i, player in pairs(excluded) do
table.remove(array, table.find(array, player))
end
return if array then array else nil
end
print(getIncludedPlayers())
getIncludedPlayers() will return an array of all players in the game, that aren’t in the exclusion paramters array.
If you want to use the playernames in the excluded table, you can do something like this:
local PlayerService = game:GetService("Players")
local function getIncludedPlayers(excluded)
local nameArray = {}
local array = PlayerService:GetPlayers()
excluded = if excluded then excluded else {}
for i, player in ipairs(array) do
table.insert(nameArray, player.Name)
end
for i, playerName in pairs(excluded) do
local index = table.find(nameArray, playerName)
table.remove(nameArray, index)
table.remove(array, index)
end
return if array then array else nil
end
if its the players names you can do smth like this:
local players_names = {...} -- excluded names
for _, plr in game.Players:GetPlayers() do
if player_table[plr.Name] then
continue
end
print(plr.Name, "is not excluded")
end
i kind of want more like a result where’d i’d be able to do like
for i, v in pairs(game.Players:GetPlayers()) do
if v ~= table.find(_G.excludedplayers) then
print(v)
end
end
would want the output to be every player except for the players in the table since i’ve only just decided to add a way to exclude players i’d have to change everything if i used one of the way above