Table.Find fails to work for string

I am trying to find a specific string with table.find() but it is not working for some reason? It is a small piece of my codes script but I need help to address [‘str’] = ‘str’, when these are placed in a table its extremely helpful. But I cant address it properly
here is the code, but chopped up for effeciency:

local valid_codes = { -- Codes Player Can Use
	["BETARELEASE"] = "50*",
	["EarlyAccess2023"] = "100",
	["JUMPSTART8"] = "nil^",
}

		if table.find(valid_codes, code) then -- Checks if code is in table and not player
			remotesend:FireClient(player,'prevredeem')
		else
			remotesend:FireClient(player,'Error') -- Just sends error message
		end

in the conditional instead of

if table.find(valid_codes, code) then -- Checks if code is in table and not player

use:

if table.find(valid_codes, code[1]) then -- Checks if code is in table and not player

otherwise

local code = --you interest
if table.find(valid_codes, code) then -- Checks if code is in table and not player

Yea its not working. I dont know why

I ask: in your code what is code

The problem is you have declared a dictionary not a table.

2 Likes

The input is ‘BETARELEASE’ I dont really use otherwise

If I saw something strange there is but I didn’t understand :rofl: :rofl:
the tables are

local tabla = {"xd"
"xdd"
"soy hombre"
}

Thats specifically what I dont understand and need help with

I don’t totally know what your valid_codes are but maybe you want this?

local valid_codes = { -- Codes Player Can Use
	"BETARELEASE",
	"EarlyAccess2023",
	"JUMPSTART8",
}

		if table.find(valid_codes, code) then -- Checks if code is in table and not player
			remotesend:FireClient(player,'prevredeem')
		else
			remotesend:FireClient(player,'Error') -- Just sends error message
		end

It’s a table, not a dictionary so I’m not sure if that would work. You can try, however, making your own function which loops and looks for the target string.

local function findstringfromdictionary(string, dictionary)
    for id, value in pairs(dictionary) do
        if value == dictionary then
            return print("Found string:", value, "with the id of:", id)
        end
    end
end
1 Like

I need the second part because the first stats the name, and the second one states its value.

What am i using string for in this function? I dont understand why this would call a target string

Okay then:

local valid_codes = { -- Codes Player Can Use
	["BETARELEASE"] = "50*",
	["EarlyAccess2023"] = "100",
	["JUMPSTART8"] = "nil^",
}

		if valid_codes[code] then -- Checks if code is in table and not player
			remotesend:FireClient(player,'prevredeem')
		else
			remotesend:FireClient(player,'Error') -- Just sends error message
		end

valid_codes[code] will also be the value.

1 Like

It has worked! Thank you so much for the help.

Yes, sorry. I didn’t noticed that I wrote dictionary instead of string.

local valid_codes = { -- Codes Player Can Use
	["BETARELEASE"] = "50*",
	["EarlyAccess2023"] = "100",
	["JUMPSTART8"] = "nil^",
}

local function findstringfromdictionary(string, dictionary)
    for id, value in pairs(dictionary) do
        if id == string then
            return print("Player gets:", value, " For using the code:", id)
        end
    end
end
findstringfromdictionary("BETARELEASE",valid_codes)

Here’s the updated version and the expected output will be:

Player gets:	50*	 For using the code:	BETARELEASE

oh well and yeah hahaha i forgot the way @quakage took existed, sorry. lol

1 Like

Thanks for the fast output! thats very helpful actually. I might just steal this function for later

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.