Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you check all the values in a table?

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)

1 comment

0

Please put your code into a code block, it is hard to understand in un-formatted form.

1 answer

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

1 comment

0

Problem. value is unlikely to be 'Value', because Value type Instances return the new value instead of the property that changed.

This discussion is preserved as it was. New answers, comments, and votes are closed.