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

How do you check all the values in a table?

Asked by 9 years ago

Say I was trying to sort out a single value from a table, and match it up with another value from some other script (Like an IntValue, string value.) Would this work, or would I need some modifications?

local TVON = script.Parent["textVal-ObjName"] local tableofItems = { "item1";"item2";"item3";"item4"; } TVON.Changed:connect(function() --when the value changes. local name = TVON.Value if name.Value == tableofItems then --codehere end end)

0
Please put your code into a code block, it is hard to understand in un-formatted form. TheDeadlyPanther 2460 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Here is what you do:

local TVON = script.Parent["textVal-ObjName"]
local tableofItems = { "item1","item2","item3","item4"}

TVON.Changed:connect(function(value) --when the value changes.
    local p = TVON[value]
    if value == "Value" then -- I didn't check with p, because it might cause a bug #SafetyFirst
        for _,v in pairs (tableofitems) do
            local name = tostring(p)
            if name == v then
                -- code
            end
        end
    end
end)

That should work. Let me explain it:

The local 'p' gets the property of 'TVON' that changed.

The 'value' is the property that changed. It checks to see if 'value' is called "Value", then goes through the table's items, checking to see if one of them is the same as 'p' s value.

The tostring gets the value of 'p'.

0
Problem. value is unlikely to be 'Value', because Value type Instances return the new value instead of the property that changed. User#6546 35 — 9y
Ad

Answer this question