Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How check if the player is not in the table?

Asked by 4 years ago
Edited 4 years ago

Well, I'm trying to create a script to enter a table, but when checking if the player is on the table so as not to insert it again, it doesn't just check it, can someone help me?

My script is in module:

local module = {}


module.Players = {}

module.Click = function(Nick)
    if not module.Players[Nick] then
        table.insert(module.Players,#module.Players + 1,Nick)

    end
end

return module

2 answers

Log in to vote
0
Answered by 4 years ago

It's simple,

if not module.Players[Nick] then
module.Players[Nick] = true
end

Make the value equal true instead of inserting it though you can insert it AND make it true, Please make sure you check the wiki before you answer 80% sure this is a troll.

0
This renames the player name to true, not work guilherme58542 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The issue is you're trying to use a list as a dictionary. Lists values are obtained by an index (a number), and dictionaries via Strings.

So maybe, the best solution is either iterating through the table with a for loop, or turning the list into a dictionary by just adding values with a name, like this:

local module = {}

module.Players = {}

module.Click = function(Nick)
    if not module.Players[Nick.Name] then
    module.Players[Nick.Name]  = Nick
    --module.Players would look like this: {Nick = Nick}
    --To get the player, you should write module.Players[Nick.Name]
    end
end

return module

0
Not work :( https://imgur.com/vlFCXwO (Print teste 5x) guilherme58542 0 — 4y
0
Hold on... Are you using that module in several scripts? masterjosue1998 116 — 4y

Answer this question