✓ Accepted answer
Question
How to access a dictionary in ModuleScripts?
Answer
The same way you index a dictionary anywhere else.
dictionary[key]
Whats wrong with your code?
It appears you're trying to index the string "blabla" for player.Name which will not work. Try setting Blacklist to a dictionary its self, and then put the names of the players as the keys for the dictionary, and the value to true or any value with truthiness.
Example:
local configuration = {
blacklist = {
["cowboyemote"] = true
}
}
return configuration
local module = require(<module reference>)
local player = <some player> *(assume its me in this case)*
if module.blacklist[player.Name] then
print(player.Name, "is blacklisted!")
else
print(player.Name, "is not blacklisted!")
end
Should have an output of (assuming I'm the player you're checking):
cowboyemote is blacklisted!
Because my name is a key in the blacklist table, and has a truthy value set to the index, the if then statement will continue as true.
What is truthiness?
Truthiness is a property of every datatype. Think of it as a value which identifies whether the object in question really exists.
Somewhat vague answer ):
If you have a variable set to a string "hello" and use an if statement on that variable you will notice the if statement continues. This is because the string is there, it exists.
This means things like nil and false do not have truthiness.
Reading Resources
http://lua-users.org/wiki/TablesTutorial
[https://www.lua.org/manual/2.4/node3.html)(https://www.lua.org/manual/2.4/node3.html)
1 comment
Thank you!