I think what you're looking for is how to make a dictionary and how to use table.insert
https://www.robloxdev.com/articles/Table#Dictionaries
Dictionaries use keys rather than indices, which means they can't be sorted like normal tables.
This would be a valid dictionary:
local banned = {
["Builderman"] = false,
["Telamon"] = true
}
But inserting using table.insert would not be easy. I'll try to walk through why each attempt was not successful.
1 - table.insert(banned,"Telamon" = true)
2 - table.insert(banned,["Telamon"] = true)
1 and 2 are the same, but 1 uses sugar syntax which is possible for your convenience. Table.insert has two parameters: the table, and the value you are inserting. Telamon=true is a statement, so you unfortunately can't insert it as if it were a value.
3 - table.insert(banned,["Telamon" = true])
This isn't exactly when you would want square brackets (not that you necessarily need them thanks to sugar syntax)
4 - table.insert(banned,"Telamon", true)
This sends three values when table.insert only has two parameters.
5 - table.insert(banned,"Telamon" == true)
== is for checking for a condition. You can think of it like this:
x = 1 means "x equals 1" (you're setting it), while if x == 2 then reads "if x is equal to 2 then" (you're checking it)
6- banned = banned + {["Telamon"] = true}
It appears that this is an attempt to concatenate a table with a dictionary, which wouldn't exactly work. String concatenation such as string1 .. string2 works, and arithmetic such as number1 + number2 works, but this would not.
So instead, here's a method that would work:
local banned = {"Builderman", "Telamon", "Shedletsky"}
function listBannedPlayers()
print("Banned players:");
for i,v in pairs(banned) do
print(v)
end
end
table.insert(banned,"Sorcus")
function unbanPlayer(username)
for i = 1,#banned do
if banned[i] == username then
table.remove(banned, i)
end
end
end
function checkBanned(username)
local isBanned = false
for i,v in pairs(username) do
if v == username then
isBanned = true
end
end
return isBanned
end
if checkBanned(player.Name) then
player:Kick("You're banned");
end
listBannedPlayers()
unbanPlayer("Sorcus")
unbanPlayer("Shedletsky")
table.insert(banned,"1x1x1x1")
listBannedPlayers()
If you have any questions comment below, if this was helpful please mark it correct or upvote
Hope this helps!
1 comment
I can confirm that works and can also confirm that your answer is detailed and I understood it. You're a god. ( I love how you picked up on banning admins xd )