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
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
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
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