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

don't know how to check if an object's name is in a table... help?

Asked by 4 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

ok i'm making a tycoon game and i'm trying to implement a save system. i have made some code that successfully saves the data (or so i've seen) but the loading data is the problem. i saved all purchased objects into a table, then inserted the purchased objects table into another table along with the players cash amount. when loading the tycoon, i pull out a clone from which i get the purchases from. then, i made some code that finds all the children of the purchases folder, then checks if the purchase's name is found in the purchased objects table. if so, move the purchase into the purchased objects folder. however, i don't know exactly how to check if the purchase's name is found in the purchased objects table......... i have tried

for i = 1, #purchases do
    local v = purchases[i]

    if tycoonData[v] then
        print('a')
    end
end

but that doesn't seem to work, no errors in the output. help please

1 answer

Log in to vote
0
Answered by 4 years ago

To check if an element is inside of a table, you can use table.find(table, element). For more information: https://developer.roblox.com/en-us/api-reference/lua-docs/table

Here is the solution:

for i = 1, #purchases do
    local v = purchases[i]

    if table.find(tycoonData, v) then
        print('a')
    end
end

Hope this helped

Ad

Answer this question