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

From a table randomly select any key with a specific value range?

Using the table posted below I would like to find every dictionary key with a specific value ranging from 0 to 1 (A to D) and ignore the rest (E to H). Can anyone give me advice as to how I can approach this?

ExampleTable = {
	["A"] = 0,
	["B"] = 0,
	["C"] = 1,
	["D"] = 1,
	["E"] = 2,
	["F"] = 2,
	["G"] = 3,
	["H"] = 3,
}

Answered by yHasteeD

1 answer

With the example provided, something like this should work:

for i,v in pairs(ExampleTable) do
	if i == "A" or i == "B" or i == "C" or i == "D" then -- Checking if the key is A to D
		print(v) -- Printing the value
	end
end

2 comments

0

or you could just math.random it

0

@Arkrei you can't use math.random() on a table with string keys (dictionary), it only works on arrays

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