So I'm making a ban script and I can't figure out how to get names from the table of banned players
i tried this it didn't work:
if player.Name == table.find(banned) then
(banned is table/list of banned players)
How could I do this?
table.find()
takes more than one variable, it accepts the table (haystack) you're searching within and a search (needle) string
for example
if player.Name == table.find(banned) then
will work but it will return either nil
or simple error out to your output as you've discovered.
to fix this you need to specify the needle or in your case the player.name
. To do this simply change what you have to something like this:
if table.find(banned,player.Name) ~= nil then -- do stuff end
This will search your banned list for the player.Name and return the index of where the name if it exists in your banned list if it does not exist in the list it will return as a nil
You can also specify where to start the search in your list, for instance if you know something's at the end of your list but don't want to cycle through all the list for some reason you can call the function like:
if table.find(banned,player.Name,25) ~= nil then -- do stuff end
The search will start it search from the index 25 onwards to the end of the table/list
if you need more reference you can look up the table.functions on the roblox wiki here: https://developer.roblox.com/en-us/api-reference/lua-docs/table
hope this helps! :)