Find The Most Value That ValueObject Have

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? hi, i want to know that what is the most value that valueobject have

  2. What is the issue? but my current script having abit issue

  3. What solutions have you tried so far? keep research but still dont found anything help

you can see that block has color different
Every Black Color Have “1” NumberValue
Every Red Block Have “3” NumberValue

and i want to know if Black Color Have More Than Red Color

local function FindMostTag()
		for i, v in pairs(ReplaceTag) do
			local TagCount = 0
			local TagNumber = 0

			for i, TagBlock in pairs(MapFolder:GetChildren()) do
				local TagBlockValue = TagBlock:WaitForChild("Tag")

				if TagBlockValue and TagBlockValue.Value ~= 0 then
					if TagNumber == 0 then
						TagCount += 1
						TagNumber = TagBlockValue.Value
					end

					if TagNumber ~= 0 and TagNumber == TagBlockValue.Value then
						TagCount += 1
					elseif TagNumber ~= 0 and TagNumber ~= TagBlockValue.Value then
					end
				end
			end

			MostTag[TagNumber] = TagCount
		end
	end

this is my script but this script will only count the first value it found, so if It Have 3 Red Block, 10 Black Block but it found the red block first black block will never count on the function

I don’t get it if all you’re doing is getting the highest value why do all of this stuff. Or are you trying to sort them on the table?

Probably because you are replacing it, if all of the tagnumber of the black block is one then you are replacing the first value in the table, why not just append the tagcount and the tagnumber; table.insert(MostTag, {TagNumber, TagCount}).

1 Like
local function SortNumbers(Folder)
	local Values = {}
	for _, Value in ipairs(Folder:GetChildren()) do
		if Value:IsA("IntValue") or Value:IsA("NumberValue") then
			table.insert(Values, Value)
		end
	end
	
	table.sort(Values, function(Left, Right)
		return Left.Value > Right.Value
	end)
	return Values
end
1 Like