-- Function to find issues in a large table
local function findIssuesInTable(t)
local issues = {
nilValues = {},
duplicates = {},
specificValueConditions = {},
}
-- Check for nil values and duplicates
local seen = {}
for i, v in ipairs(t) do
if v == nil then
table.insert(issues.nilValues, i)
end
if seen[v] then
table.insert(issues.duplicates, {value = v, indices = {seen[v], i}})
else
seen[v] = i
end
end
-- Example of specific value condition: check for negative numbers
for i, v in ipairs(t) do
if type(v) == "number" and v < 0 then
table.insert(issues.specificValueConditions, {index = i, value = v})
end
end
return issues
end
-- Example usage
local exampleTable = {1, 2, nil, 4, 2, -5, 6, nil, -3}
local issues = findIssuesInTable(exampleTable)
print("Nil values found at indices:")
for _, index in ipairs(issues.nilValues) do
print(index)
end
print("Duplicates found:")
for _, dup in ipairs(issues.duplicates) do
print("Value: " .. dup.value .. ", Indices: " .. table.concat(dup.indices, ", "))
end
print("Specific value conditions (negative numbers) found:")
for _, cond in ipairs(issues.specificValueConditions) do
print("Index: " .. cond.index .. ", Value: " .. cond.value)
end
You can’t search the instance using the string name associated with it. So you have to convert "wall" to the associated instance and look for that. Another solution is to check all the values:
local function find(t: {Instance}, name: string): Instance?
for _, v in pairs(t) do
if v.Name == name then return v end
end
return nil
end
print(find(frontitems, "wall"))
Don’t know what’s the smart word for it, but basically you are marking that this specific variable is a string/boolean/instance/whatever datatype, which just helps you in the future understand what the heck are all these words. Code editor also automatically warns you if you are parsing an incorrect datatype and shows additional hints. It’s like comments on steroid
These “:” are called type annotations and doesn’t affect the way the code runs
“_” is kind of a “throwaway variable”, which basically means that you are not planning to use this variable in any way. Also has no effect
The code below is the same and you probably understand it more. All these fancy stuff is usually used by more expirienced scripters for easier communication between them
local function find(t, name)
for i, v in pairs(t) do
if v.Name == name then return v end
end
return nil
end
print(find(frontitems, "wall"))
thank you for explaining everything with details and being so patient im still very new to coding and i’ve been stuck with this problem for so long so im really happy to have this mysterious problem explained
so again thank you for explaining the details and for your patience, have a nice night
thank you aswell for giving me the the solution i needed and went out of your way to help me, im very thankful for your help and wish you alot of luck in what you are doing
No problem. Everyone has to start from somewhere. All these stuff just comes in naturally (at least for me). If you really want to, you can pm me in the future for help
again, thank you for explaining the problem to me and for your time and patience, you do not know how thankful i am for someone finally having an answer to this problem i had. anyways, goodnight and thank you again