Help with my Finding Game

So, I’ve been trying to cook up a system that sets a textlabel to the number that it is placed in the scrolling frame. The issue is, the numbers are jumbled up…

Here’s a screenshot :

This is what I wrote :
itemButton.CubeNum.Text = i
(It was in a for loop. itemButton = cube button in index. CubeNum = the number at the top right of each button.)

Any help would be appreciated!

1 Like

A couple of things could be causing this problem.

  1. If you only show cubes unlocked it might still count the ones that arent showing.
  2. It might count other cubes that aren’t showing.

Do you mind showing the script?

Use ```lua and then at the end use it again without the word lua. Also please show the full code and not a snippet.

local indexMenu = script.Parent
local collected = indexMenu:WaitForChild("CubesCollected")

local mainFrame = indexMenu:WaitForChild("MainFrame")
local scrollingFrame = mainFrame:WaitForChild("List")

local UIGridLayout = scrollingFrame:WaitForChild("UIGridLayout")

local info = mainFrame:WaitForChild("CubeInfo")
local difficultiesFrame = mainFrame:WaitForChild("DifficultyChart")

local Players = game:GetService('Players')
local player = Players.LocalPlayer
local cubesCollected = player:WaitForChild("cubesCollected")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cubesFile = ReplicatedStorage:WaitForChild("Cubes")

local tweenService = game:GetService("TweenService")

local tweenInfo =, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut, 0, false, 0)

local tweenClose = tweenService:Create(indexMenu, tweenInfo, {Position =, 0, 1.5, 0)})

local filterType ="StringValue", player)
filterType.Name = "filterType"
filterType.Value = "All"

local difficultyColors = {
	Color3.fromHex("#a7ffa2"), -- Beginner
	Color3.fromHex("#00e300"), -- Easy
	Color3.fromHex("#ffff00"), -- Medium
	Color3.fromHex("#ff9d00"), -- Hard
	Color3.fromHex("#e10000"), -- Difficult
	Color3.fromHex("#790000"), -- Challenging
	Color3.fromHex("#000000"), -- Intense
	Color3.fromHex("#ff00ea"), -- Remorseless
	Color3.fromHex("#0003c8"), -- Insane
	Color3.fromHex("#0082c8"), -- Extreme
	Color3.fromHex("#00fbff"), -- Terrifying
	Color3.fromHex("#ffffff"), -- Catastrophic

local difficulties = {

local areaColors = {
	Color3.fromHex("#b97619"), -- Cube Town

local areas = {
	"Cube Town",

local filters = {

local totalCount = 0

for i, v in pairs(cubesFile:GetChildren()) do
	totalCount = totalCount + 1

local collectedCount = 0

for i, v in pairs(cubesCollected:GetChildren()) do

	collectedCount = collectedCount + 1


collected.Text = collectedCount.."/"..totalCount.." Collected (".. math.round((collectedCount / totalCount) * 100) .."%)"
script.Parent.Parent.ActivateIt.TextLabel.Text = collectedCount.."/"..totalCount.." (".. math.round((collectedCount / totalCount) * 100) .."%)"

for i, item in pairs(cubesFile:GetChildren()) do
	local itemName = item.Name
	local difficulty = item.difficulty.Value
	local hint = item.hint.Value
	local name =
	local description = item.description.Value
	local area = item.area.Value
	local creator = item.creator.Value
	local itemButton = script.TemplateCube:Clone()
	itemButton.Parent = scrollingFrame
	itemButton.Name = itemName
	itemButton.Difficulty.BackgroundColor3 = difficultyColors[difficulty]
	itemButton.BackgroundColor3 = difficultyColors[difficulty]
	itemButton.CubeName.Text = name
	if cubesCollected:FindFirstChild(itemName) then

		itemButton.ViewportFrame.ImageColor3 =, 1, 1)
		itemButton.ViewportFrame.ImageTransparency = 0
		itemButton.ViewportFrame.ImageColor3 =, 0.15, 0.15)
		itemButton.ViewportFrame.ImageTransparency = 0.5
	for i, folder in pairs(workspace.CubeModels:GetChildren()) do

		for i, cube in pairs(folder:GetChildren()) do
			if itemButton.ViewportFrame:FindFirstChild(cube.Name) then



	local VPclone = nil
	for i, folder in pairs(workspace.CubeModels:GetChildren()) do

		VPclone = folder:FindFirstChild(itemButton.Name):Clone()

	VPclone.Parent = itemButton.ViewportFrame
	if VPclone:IsA("Part") then
		VPclone.Position =, -9.421, 56.31)
		VPclone.Orientation =, -180, 0)
		VPclone:SetPrimaryPartCFrame(, -9.421, 56.31) * CFrame.Angles(0, math.rad(-180), 0))
	itemButton.LayoutOrder = difficulty
	itemButton.CubeNum.Text = #cubesFile:GetChildren() - (#cubesFile:GetChildren() - i)
	UIGridLayout.SortOrder = Enum.SortOrder.LayoutOrder
		for i, folder in pairs(workspace.CubeModels:GetChildren()) do
			for i, cube in pairs(folder:GetChildren()) do

				if info.ViewportFrame:FindFirstChild(cube.Name) then


		local VPclone2 = nil
		for i, folder in pairs(workspace.CubeModels:GetChildren()) do
			VPclone2 = folder:FindFirstChild(itemButton.Name):Clone()
		VPclone2.Parent = info.ViewportFrame
		if VPclone2:IsA("Part") then

			VPclone2.Position =, -9.421, 56.31)
			VPclone2.Orientation =, -180, 0)


			VPclone2:SetPrimaryPartCFrame(, -9.421, 56.31) * CFrame.Angles(0, math.rad(-180), 0))

		info.CubeName.Text = name
		info.CubeHint.ScrollingFrame.Text.Text = "Hint: "..hint
		info.Difficulty.BackgroundColor3 = difficultyColors[difficulty]
		info.CubeDesc.ScrollingFrame.Text.Text = description
		info.Difficulty.Text = difficulties[difficulty]
		info.Area.Text = areas[area]
		info.Area.BackgroundColor3 = areaColors[area]
		info.Creator.Text = "Made By : "..creator
		scrollingFrame.Visible = false
		difficultiesFrame.Visible = false
		info.Visible = true


	collectedCount = collectedCount + 1
	collected.Text = collectedCount.."/"..totalCount.." Collected (".. math.round((collectedCount / totalCount) * 100) .."%)"
	script.Parent.Parent.ActivateIt.TextLabel.Text = collectedCount.."/"..totalCount.." (".. math.round((collectedCount / totalCount) * 100) .."%)"

	local childButton = scrollingFrame:FindFirstChild(child.Name)
	childButton.ViewportFrame.ImageColor3 =, 1, 1)
	childButton.ViewportFrame.ImageTransparency = 0

	childButton.LayoutOrder = cubesFile:FindFirstChild(child.Name).difficulty.Value
	--childButton.CubeNum.Text = child.LayoutOrder


Which part is the for loop you mentioned earlier?

for i, item in pairs(cubesFile:GetChildren()) do

Now it looks like this :

	itemButton.CubeNum.Text = #cubesFile:GetChildren() - (#cubesFile:GetChildren() - i)

If this is the line of code you’re having trouble with then what’s the point in all the extra stuff instead of this?

	itemButton.CubeNum.Text = i

Well, I can show you what im aiming for :

Okay so it looks like the script isn’t doing them in numerical order.
You could manually give them a number but that’s not practical.

Yeah, I’m looking for an efficient way to do it.

This might be part of a fix.

if toNumber(itemButton.CubeNum.Text) > #difficulty:GetChildren() then
--do some stuff

Wait, for the cubes that are the same difficulty, it’ll be, for example, 1 for all the cubes that are light green

Okay I thought of a fix.
Check if the number is bigger than the last one that you did of that difficulty and set the text to +1 of that number

if lastCube then
	if toNumber(itemButton.CubeNum.Text) > toNumber(lastCube.CubeNum.Text) then
		itemButton.CubeNum.Text = toNumber(lastCube.CubeNum.Text) + 1

Getting the last cube should be as simple as setting a lastCube variable before the loop and then setting the lastCube to the current cube at the end of the loop.

local lastCube = nil
--[[loop stuff
stuff inside loop]]
lastCube = itemButton
--end of loop

This might not be the best solution but it could work.

I’m very confused… I was just skimming through the code and it doesent seem like it would work…

Yeah, I forgot to mention you should do the last one from that DIFFICULTY. Not the last one from all difficulties.

Confused how I should implement it into my script too

Did this topic go extinct? Or not?