Is there a way to make a script detect if a player is in a table?
1 Like
What do you mean? Could you give us the table that you need to detect players in?
Also, table.find
can be very useful:
if table.find(path to table) then
print("something is in the table")
end
2 Likes
I dont know how to use it could i get a dev hub link?
You can do it on multiple ways table.find
is an easy way to do it but it’s slower than creating your own for loop and comparing each value.
table.find(TableNameHere, "IamLookingForThisString") -- returns true or false
or you can do it inside of a for loop:
for i,v in pairs(TableNameHere) do
if v == "IamLookingForThisString" then
--do your thing here
end
end
2 Likes
what do i need to do to find a player inside a table not a string im kinda new to tables
If you’re looking for objects you could always do a for loop check?
for _, plr in pairs (game.Players:GetPlayers()) do
for i = 1, #tab do
if tab[i] == plr then
print 'found player!'
end
end
end
1 Like
Instead of string in my example you put instance/object.
if table.find(table, player) then --stuff end
local playersTable = {game.Players.Player1, game.Players.Player2} -- this is the players table
local player = game.Players.PlayerNameHere -- replace PlayerNameHere with the name of the player
for i,v in pairs(playersTable) do
end