Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How check if the player is not in the table?

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

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.

1 comment

0

This renames the player name to true, not work

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

2 comments

0

Not work :( https://imgur.com/vlFCXwO (Print teste 5x)

0

Hold on... Are you using that module in several scripts?

This discussion is preserved as it was. New answers, comments, and votes are closed.